在router文件夾下新建你要分區的模塊例如 登陸 訂單模塊vue
新建文件 logn.router.js order.router.jsvue-router
代碼以下:ui
export default { path: '/login', name: 'login', component: () => import('../views/login.vue'), children: [ ] }
order.router.js 也是如此spa
而後在 router.js中 引入 login.router.js、order.router.jscode
代碼以下:component
import Vue from "vue"; import Router from "vue-router"; import Login from './routers/login.router.js'; import Order from './routers/order.router.js'; import Home from './views/home/home'; Vue.use(Router); export default new Router({ routes: [ { path: '/home', name: 'home', component: Home}, Login, Order ] });
login.rotuer.js、order.router.js不變router
在router.js中 修改以下:blog
import Vue from "vue"; import Router from "vue-router"; import Home from './views/home/home'; Vue.use(Router); const routerList = []; function importAll (r) { r.keys.forEach( key => routerList.push(r(key).default); ); } importAll(require.context('./router', true, /\.router\.js/)); export default new Router({ routes: [ { path: '/home', name: 'home', component: Home} ] });