Vue3动态路由-递归遍历权限路由

185 阅读1分钟
function dynamicRouter(roleList) {
    let asyncRouter = []
    roleList.forEach((itemRouter, index) => {
        const path = [...manageRoutesMap]
        //匹配权限路径
        const authRoute = path.find((v) => v.path === itemRouter.resRoute)
        //处理后端返回的字段
        asyncRouter.push({
            path: itemRouter.resRoute,
            name: itemRouter.name,
            children: itemRouter.subs.length > 0 ? itemRouter.subs : null,
            component: authRoute?.component,
        })
        if (itemRouter.subs && itemRouter.subs.length > 0) {
            asyncRouter[index].children = dynamicRouter(itemRouter.subs)
        }
    })
    return asyncRouter
}