vue-router动态添加路由,利⽤$router.addRoutes()常⽤于⽤户权限控制
// 映射关系const compMap = {'Home': () => import("./view/Home.vue")}// 异步获取路由api.getRoutes().then(routes => {const routeConfig = routes.map(route => mapComponent(route));router.addRoutes(routeCon
·
// 映射关系
const compMap = {
'Home': () => import("./view/Home.vue")
}
// 异步获取路由
api.getRoutes().then(routes => {
const routeConfig = routes.map(route => mapComponent(route));
router.addRoutes(routeConfig);
})
// 递归替换
function mapComponent(route) {
route.component = compMap[route.component];
if(route.children) {
route.children = route.children.map(child => mapComponent(child))
}
return route
}
更多推荐
已为社区贡献1条内容
所有评论(0)