Commit df8cd860514f32f44847dcf724f0737ed4d8b9e0
1 parent
448a4c28
fix(router): loss `directory` route
修复"目录"路由丢失的问题 fix: #722
Showing
1 changed file
with
5 additions
and
5 deletions
src/router/helper/routeHelper.ts
... | ... | @@ -2,7 +2,7 @@ import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types'; |
2 | 2 | import type { Router, RouteRecordNormalized } from 'vue-router'; |
3 | 3 | |
4 | 4 | import { getParentLayout, LAYOUT } from '/@/router/constant'; |
5 | -import { cloneDeep } from 'lodash-es'; | |
5 | +import { cloneDeep, omit } from 'lodash-es'; | |
6 | 6 | import { warn } from '/@/utils/log'; |
7 | 7 | import { createRouter, createWebHashHistory } from 'vue-router'; |
8 | 8 | |
... | ... | @@ -73,7 +73,7 @@ export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModul |
73 | 73 | } |
74 | 74 | route.children && asyncImportRoute(route.children); |
75 | 75 | }); |
76 | - return (routeList as unknown) as T[]; | |
76 | + return routeList as unknown as T[]; | |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
... | ... | @@ -95,7 +95,7 @@ export function flatMultiLevelRoutes(routeModules: AppRouteModule[]) { |
95 | 95 | function promoteRouteLevel(routeModule: AppRouteModule) { |
96 | 96 | // Use vue-router to splice menus |
97 | 97 | let router: Router | null = createRouter({ |
98 | - routes: [(routeModule as unknown) as RouteRecordNormalized], | |
98 | + routes: [routeModule as unknown as RouteRecordNormalized], | |
99 | 99 | history: createWebHashHistory(), |
100 | 100 | }); |
101 | 101 | |
... | ... | @@ -103,7 +103,7 @@ function promoteRouteLevel(routeModule: AppRouteModule) { |
103 | 103 | addToChildren(routes, routeModule.children || [], routeModule); |
104 | 104 | router = null; |
105 | 105 | |
106 | - routeModule.children = routeModule.children?.filter((item) => !item.children?.length); | |
106 | + routeModule.children = routeModule.children?.map((item) => omit(item, 'children')); | |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Add all sub-routes to the secondary route |
... | ... | @@ -120,7 +120,7 @@ function addToChildren( |
120 | 120 | } |
121 | 121 | routeModule.children = routeModule.children || []; |
122 | 122 | if (!routeModule.children.find((item) => item.name === route.name)) { |
123 | - routeModule.children?.push((route as unknown) as AppRouteModule); | |
123 | + routeModule.children?.push(route as unknown as AppRouteModule); | |
124 | 124 | } |
125 | 125 | if (child.children?.length) { |
126 | 126 | addToChildren(routes, child.children, routeModule); | ... | ... |