vue-router vue2 动态路由添加子路由

865 阅读1分钟

添加路由

   this.$router.addRoute(msg1,msg2)
   接受2个参数,参数1是父路由的名称,参数2是实际添加的子路由,如果添加的是同级路由可以只传参数2
   const msg2={
      name:"123",
      path:"/123",
      component:import=>("./123.vie"),
   }
   this.$router.addRoute(msg2)
动态添加的路由在this.$router里面获取不到,要使用this.$router.getRoutes()来获取所有路由列表