sync: 同步管理前端 v1.0.4 并脱敏
This commit is contained in:
@@ -28,7 +28,7 @@ async function generateAccessible(
|
||||
// 生成路由
|
||||
const accessibleRoutes = await generateRoutes(mode, options);
|
||||
|
||||
const root = router.getRoutes().find((item) => item.path === '/');
|
||||
const root = findRootRoute(router);
|
||||
|
||||
// 获取已有的路由名称列表
|
||||
const names = root?.children?.map((item) => item.name) ?? [];
|
||||
@@ -71,6 +71,34 @@ async function generateAccessible(
|
||||
return { accessibleMenus, accessibleRoutes };
|
||||
}
|
||||
|
||||
function findRootRoute(router: GenerateMenuAndRoutesOptions['router']) {
|
||||
const routes = router.getRoutes();
|
||||
|
||||
// Route paths are not unique: an empty-path backend child can normalize to '/'.
|
||||
const namedRoot = routes.find((item) => item.name === 'Root');
|
||||
if (namedRoot) {
|
||||
return namedRoot;
|
||||
}
|
||||
|
||||
// Keep a path-independent fallback for applications that rename the core route.
|
||||
const titledRoot = routes.find((item) => item.meta.title === 'Root');
|
||||
if (titledRoot) {
|
||||
return titledRoot;
|
||||
}
|
||||
|
||||
const childNames = new Set(
|
||||
routes.flatMap((item) => item.children?.map((child) => child.name) ?? []),
|
||||
);
|
||||
const topLevelLayouts = routes.filter(
|
||||
(item) =>
|
||||
item.children?.length &&
|
||||
!item.aliasOf &&
|
||||
(item.name === undefined || !childNames.has(item.name)),
|
||||
);
|
||||
|
||||
return topLevelLayouts.length === 1 ? topLevelLayouts[0] : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate routes
|
||||
* @param mode
|
||||
|
||||
Reference in New Issue
Block a user