vue路由分模块
router文件夹下index.js
import Vue from 'vue' import Router from 'vue-router' import Layout from '@/home' Vue.use(Router) const routerList = [] // 引入路由 function importAll(r) { r.keys().forEach( key => routerList.push(r(key).default) ); } // require.context是webpack的API,动态引入文件 // 参数1.路径2.是否匹配子集3.规则(此规则需以.router.js结尾) importAll(require.context('./', false, /\.router\.js/)) export const constantRoutes = [ ...routerList { path: '/home', name: 'home', component: home }, ] const router = new Router({ // mode: 'history', // require service support scrollBehavior: () => ({ y: 0 }), routes: constantRoutes }) export default router
子模块login.router.js
export default { path: '/login', name: 'login', component: () => import('@/login.vue'), children: [ ] }

浙公网安备 33010602011771号