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
feature/20260628/refactor-frontend-modernization
Lxy 2 weeks ago
parent ee1338f9c3
commit f80d90a9de

@ -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),

Loading…
Cancel
Save