工欲善其事必先利其器
This commit is contained in:
@@ -2,22 +2,22 @@ import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
const ctx = import.meta.glob('../views/App*.vue')
|
||||
const ctx = import.meta.glob('../views/App*.vue', {eager: true})
|
||||
const router = new VueRouter({
|
||||
mode: 'history', routes: [{
|
||||
path: '/', name: 'home',
|
||||
}]
|
||||
})
|
||||
const routes = []
|
||||
await Promise.all(ctx.keys().map(ctx)).then(file => {
|
||||
console.log(ctx)
|
||||
await Promise.all(Object.values(ctx).map(file => {
|
||||
if (file.default) {
|
||||
const {name, label = name, path} = file.default
|
||||
let {name, label = name, path = name} = file.default
|
||||
routes.push({name, path, label})
|
||||
router.addRoute({
|
||||
path, name, component: file.default
|
||||
})
|
||||
return router.addRoute("home", {path, name, component: () => file.default})
|
||||
|
||||
}
|
||||
}).then(() => {
|
||||
})).then(() => {
|
||||
localStorage.setItem('routes', JSON.stringify(routes))
|
||||
})
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user