思路
一:通过接口获取路由配置(这个就不叙述了 不同得公司返回得东西都不太一样)
主要有以下几项
1.tabName 名字
2.path 链接
3.对应要加载组件得名称(根据这个去决定加载什么组件)
4是否是第一级得路由 这么一个字段
二,添加
添加一级路由
// 1级路由
let obj={
path: "/login2",
component:resolve =>require(['../page/login'],resolve),
name:"登录2",
meta: { title: "登录2"},
}
this.$router.options.routes.push(obj)
//重新挂载路由
this.$router.addRoutes(this.$router.options.routes)
添加二级路由
// 二级路由
let obj1={
path: "login2",
component:resolve =>require(['../page/login'],resolve),
name:"登录2",
meta: { title: "登录2"},
}
for(let i in this.$router.options.routes){
if(this.$router.options.routes[i].name=='登录'){ //这个是判断放在哪个路由得二级下面
if(this.$router.options.routes[i].children){
}else{
this.$router.options.routes[i].children=[]
}
this.$router.options.routes[i].children.push(obj1)
}
}
//重新挂载路由
this.$router.addRoutes(this.$router.options.routes)