vue-router 动态添加 路由


 动态添加路由可以用了做权限管理。登录后服务器端返回权限菜单,前端动态添加路由  然后在设置菜单

 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
View Code

我的路由文件:

export default new Router({
  routes: [
    {
      path: '/',
 
      component: index,
    },
    {
      path: '/login',
      name: 'login',
      component: login
    }

})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM