Commit 04fb4c0365879949a0b71d75801af41fe400f0cd
1 parent
74dfc60e
fix: 路由顶级非目录菜单直接显示
Showing
2 changed files
with
40 additions
and
20 deletions
yudao-ui-admin-vue3/src/utils/routerHelper.ts
| @@ -65,30 +65,49 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord | @@ -65,30 +65,49 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord | ||
| 65 | redirect: route.redirect, | 65 | redirect: route.redirect, |
| 66 | meta: meta | 66 | meta: meta |
| 67 | } | 67 | } |
| 68 | - // 目录 | ||
| 69 | - if (route.children) { | 68 | + //处理顶级非目录路由 |
| 69 | + if (!route.children && route.parentId == 0 && route.component) { | ||
| 70 | data.component = Layout | 70 | data.component = Layout |
| 71 | - data.redirect = getRedirect(route.path, route.children) | ||
| 72 | - // 外链 | ||
| 73 | - } else if (isUrl(route.path)) { | ||
| 74 | - data = { | ||
| 75 | - path: '/external-link', | ||
| 76 | - component: Layout, | ||
| 77 | - meta: { | ||
| 78 | - name: route.name | ||
| 79 | - }, | ||
| 80 | - children: [data] | ||
| 81 | - } as AppRouteRecordRaw | ||
| 82 | - // 菜单 | ||
| 83 | - } else { | ||
| 84 | - // 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致) | 71 | + data.meta = {} |
| 72 | + data.name = toCamelCase(route.path, true) + 'Parent' | ||
| 73 | + data.redirect = '' | ||
| 74 | + const childrenData: AppRouteRecordRaw = { | ||
| 75 | + path: '', | ||
| 76 | + name: toCamelCase(route.path, true), | ||
| 77 | + redirect: route.redirect, | ||
| 78 | + meta: meta | ||
| 79 | + } | ||
| 85 | const index = route?.component | 80 | const index = route?.component |
| 86 | ? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component)) | 81 | ? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component)) |
| 87 | : modulesRoutesKeys.findIndex((ev) => ev.includes(route.path)) | 82 | : modulesRoutesKeys.findIndex((ev) => ev.includes(route.path)) |
| 88 | - data.component = modules[modulesRoutesKeys[index]] | ||
| 89 | - } | ||
| 90 | - if (route.children) { | ||
| 91 | - data.children = generateRoute(route.children) | 83 | + childrenData.component = modules[modulesRoutesKeys[index]] |
| 84 | + data.children = [childrenData] | ||
| 85 | + } else { | ||
| 86 | + // 目录 | ||
| 87 | + if (route.children) { | ||
| 88 | + data.component = Layout | ||
| 89 | + data.redirect = getRedirect(route.path, route.children) | ||
| 90 | + // 外链 | ||
| 91 | + } else if (isUrl(route.path)) { | ||
| 92 | + data = { | ||
| 93 | + path: '/external-link', | ||
| 94 | + component: Layout, | ||
| 95 | + meta: { | ||
| 96 | + name: route.name | ||
| 97 | + }, | ||
| 98 | + children: [data] | ||
| 99 | + } as AppRouteRecordRaw | ||
| 100 | + // 菜单 | ||
| 101 | + } else { | ||
| 102 | + // 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致) | ||
| 103 | + const index = route?.component | ||
| 104 | + ? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component)) | ||
| 105 | + : modulesRoutesKeys.findIndex((ev) => ev.includes(route.path)) | ||
| 106 | + data.component = modules[modulesRoutesKeys[index]] | ||
| 107 | + } | ||
| 108 | + if (route.children) { | ||
| 109 | + data.children = generateRoute(route.children) | ||
| 110 | + } | ||
| 92 | } | 111 | } |
| 93 | res.push(data) | 112 | res.push(data) |
| 94 | } | 113 | } |
yudao-ui-admin-vue3/types/router.d.ts