// 映射关系
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
}
Logo

前往低代码交流专区

更多推荐