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