修复路由

This commit is contained in:
2024-06-17 21:55:16 +08:00
parent 619530eb18
commit 48da2f12f6
4 changed files with 13 additions and 20 deletions

View File

@@ -3,21 +3,15 @@ import VueRouter from 'vue-router'
Vue.use(VueRouter)
const ctx = import.meta.glob('../views/App*.vue', {eager: true})
const router = new VueRouter({
mode: 'history', routes: [{
path: '/', name: 'home',
}]
})
const routes = []
console.log(ctx)
await Promise.all(Object.values(ctx).map(file => {
const routes = [{path: '/', name: 'home'}]
Object.values(ctx).map(file => {
if (file.default) {
let {name, label = name, path = name} = file.default
routes.push({name, path, label})
return router.addRoute("home", {path, name, component: () => file.default})
let {name, label = name, path = `/apps/${name}`} = file.default
routes.push({name, path, label, component: file.default})
}
})).then(() => {
localStorage.setItem('routes', JSON.stringify(routes))
})
export default router
localStorage.setItem('routes', JSON.stringify(routes.slice(1).map(v => ({name: v.name, label: v.label, path: v.path}))))
export default new VueRouter({
mode: 'history', routes
})