let temp = {}, //临时路由
tree = {}, //左侧菜单
routers = [] //路由
//组装路由菜单
for (let i in arr) {
let path = arr[i].code
//组装路由
let tempRouter = {
path: path ? `/${path}` : "",
name: "",
meta: {
id: "" + arr[i].id,
parentId: arr[i].parentId,
title: arr[i].text,
iconCls: arr[i].iconCls,
pageParams: arr[i].pageParams
},
children: []
}
if (path) {
let name = path.slice(path.lastIndexOf("/"))
name = name.split('/')
tempRouter.name = name[1]
//获取组件路径
tempRouter.component = require(`@/views/${path}.vue`).default
this.$router.options.routes[1].children.push(tempRouter)
routers.push(tempRouter)
}
temp[arr[i].id] = tempRouter
}
//将子路由也添加到路由
this.$router.addRoutes(this.$router.options.routes)
网友评论