清理一下
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user