This commit is contained in:
dap
2025-03-29 22:53:47 +08:00
13 changed files with 193 additions and 27 deletions

View File

@@ -31,6 +31,9 @@ async function generateAccessible(
const root = router.getRoutes().find((item) => item.path === '/');
// 获取已有的路由名称列表
const names = root?.children?.map((item) => item.name) ?? [];
// 动态添加到router实例内
accessibleRoutes.forEach((route) => {
/**
@@ -46,7 +49,10 @@ async function generateAccessible(
if (route.children && route.children.length > 0) {
delete route.component;
}
root.children?.push(route);
// 根据router name判断如果路由已经存在则不再添加
if (!names?.includes(route.name)) {
root.children?.push(route);
}
} else {
router.addRoute(route);
}