24 lines
619 B
JavaScript
24 lines
619 B
JavaScript
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
|
|
Vue.use(VueRouter)
|
|
const ctx = require.context('../views', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy')
|
|
const router = new VueRouter({
|
|
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
|