vue权限路由
emer 发布于 2019-8-19 15:00 2031 次阅读
export function recursionRouter(userRouter = [], allRouter = []) {
var realRoutes = allRouter
.filter(item => userRouter.includes(item.name))
.map(item => ({
...item,
children: item.children
? recursionRouter(userRouter, item.children)
: null
}))
return realRoutes
}
/**
*
* @param {Array} routes 用户过滤后的路由
*
* 递归为所有有子路由的路由设置第一个children.path为默认路由
*/
export function setDefaultRoute(routes) {
routes.forEach((v, i) => {
if (v.children && v.children.length > 0) {
v.redirect = { name: v.children[0].name }
setDefaultRoute(v.children)
}
})
}