清理一下

This commit is contained in:
aixianling
2024-06-17 18:20:13 +08:00
parent 27ea4bc032
commit 07b7474af1
5 changed files with 69 additions and 105 deletions

View File

@@ -1,27 +1,23 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
Vue.use(VueRouter)
const ctx = require.context('../views', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy')
const router = new VueRouter({
mode: 'history',
base: import.meta.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/AboutView.vue')
}
]
mode: 'history', routes: [{
path: '/', name: 'home',
}]
})
const routes = []
await Promise.all(ctx.keys().map(ctx)).then(file => {
if (file.default) {
const {name, label = name, path} = file.default
routes.push({name, path, label})
router.addRoute({
path, name, component: file.default
})
}
}).then(() => {
localStorage.setItem('routes', JSON.stringify(routes))
})
export default router