動態添加路由可以用了做權限管理。登錄后服務器端返回權限菜單,前端動態添加路由 然后在設置菜單
1、vue-router 有方法router.addRoutes(routes) 動態添加更多的路由規則。參數必須是一個符合 routes 選項要求的數組。
使用方法

this.$router.options.routes[0].children.push({//插入路由 name:'list', path: 'list', component: resolve => require(['../template/list.vue'], resolve)//將組件用require引進來 }); this.$router.addRoutes(this.$router.options.routes);//調用a !
我的路由文件:
export default new Router({ routes: [ { path: '/', component: index, }, { path: '/login', name: 'login', component: login } })