Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/plugin-access/src/utils/getRuntimeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ export default (strictMode: boolean = false) =>
if (!currentRoute.unaccessible && isAllChildChildrenUnaccessible) {
currentRoute.unaccessible = true;
}

// 父节点显示/隐藏逻辑:
// 1. 遍历所有子节点,找出未设置 hideInMenu 的节点(即可见节点)
// 2. 如果没有任何可见子节点,则隐藏父节点
const hasVisibleChildren =
Array.isArray(finallyChildList) &&
finallyChildList.some((route) => !route.hideInMenu);

if (!hasVisibleChildren) {
currentRoute.hideInMenu = true;
}

if (finallyChildList && finallyChildList?.length > 0) {
return {
...currentRoute,
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-access/tests/utils/runtimeUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,30 @@ describe('TraverseModifyRoutes', () => {
traverseModifyRoutes(routes, access);
}).toThrowError();
});

it('should hide parent route when all visible children are hidden', () => {
const testRoutes = [
{
path: '/parent',
routes: [
{ path: '/child1', hideInMenu: true },
{ path: '/child2', hideInMenu: true },
{ path: '/child3', hideInMenu: true }
]
},
{
path: '/parent2',
routes: [
{ path: '/child1', hideInMenu: true },
{ path: '/child2' }
]
}
];

const result = traverseModifyRoutes(testRoutes, access);

expect(result[0].hideInMenu).toBe(true);

expect(result[1].hideInMenu).toBeUndefined();
});
});