From f80d90a9de3f75b140123a3962cb0430752079cd Mon Sep 17 00:00:00 2001 From: Lxy Date: Thu, 2 Jul 2026 00:27:06 +0800 Subject: [PATCH] fix: avoid root route conflict in dynamic route generation - getRouters returns a menu with path='/' and component='Layout' - This conflicts with the constant '/' route that redirects to '/index' - Flatten such menus to their children to preserve the original root redirect - This fixes the issue where getRouters success was followed by another /login call --- ruoyi-ui-next/src/stores/modules/permission.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ruoyi-ui-next/src/stores/modules/permission.ts b/ruoyi-ui-next/src/stores/modules/permission.ts index 371f9c9..608e7db 100644 --- a/ruoyi-ui-next/src/stores/modules/permission.ts +++ b/ruoyi-ui-next/src/stores/modules/permission.ts @@ -55,7 +55,13 @@ export const usePermissionStore = defineStore('permission', () => { function filterAsyncRouter(menuList: any[]): RouteRecordRaw[] { return menuList .filter((menu: any) => menu.visible !== '1' || menu.children) - .map((menu: any) => { + .flatMap((menu: any) => { + // 如果顶级菜单 path 是 '/' 且 component 是 Layout, + // 直接展开它的 children,避免与 constantRoutes 中的 '/' 路由冲突 + if (menu.path === '/' && menu.component === 'Layout' && menu.children) { + return filterAsyncRouter(menu.children) + } + const route: any = { path: menu.path, name: menu.name || convertRouteName(menu.path),