fix: 🐛 (route)修复父级菜单 alwaysShow 无效问题

- 修改 processRoutes 函数,如果 children 为 undefined,则原样返回
This commit is contained in:
zimo493
2025-09-08 09:09:17 +08:00
parent 0323ca36c0
commit e84d87d403

View File

@@ -21,7 +21,8 @@ export const usePermissionStore = defineStore("permission", () => {
async function generateRoutes(): Promise<RouteRecordRaw[]> {
try {
const data = await MenuAPI.getRoutes(); // 获取当前登录人拥有的菜单路由
const dynamicRoutes = parseDynamicRoutes(processRoutes(data));
const processRouteList = processRoutes(data); // 处理后的路由数据
const dynamicRoutes = parseDynamicRoutes(processRouteList);
routes.value = [...constantRoutes, ...dynamicRoutes];
@@ -117,8 +118,8 @@ const processRoutes = (routes: RouteVO[], isTopLevel: boolean = true): RouteVO[]
return {
...args,
component: isTopLevel || component !== "Layout" ? component : undefined,
// 递归处理children标记为非顶层
children: children && children.length > 0 ? processRoutes(children, false) : [],
// 递归处理children标记为非顶层 todo 原样返回 childrenundefined
children: children && children.length > 0 ? processRoutes(children, false) : children,
};
});
};