Skip to content

Commit df8cd86

Browse files
committed
fix(router): loss directory route
修复"目录"路由丢失的问题 fix: #722
1 parent 448a4c2 commit df8cd86

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/router/helper/routeHelper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types';
22
import type { Router, RouteRecordNormalized } from 'vue-router';
33

44
import { getParentLayout, LAYOUT } from '/@/router/constant';
5-
import { cloneDeep } from 'lodash-es';
5+
import { cloneDeep, omit } from 'lodash-es';
66
import { warn } from '/@/utils/log';
77
import { createRouter, createWebHashHistory } from 'vue-router';
88

@@ -73,7 +73,7 @@ export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModul
7373
}
7474
route.children && asyncImportRoute(route.children);
7575
});
76-
return (routeList as unknown) as T[];
76+
return routeList as unknown as T[];
7777
}
7878

7979
/**
@@ -95,15 +95,15 @@ export function flatMultiLevelRoutes(routeModules: AppRouteModule[]) {
9595
function promoteRouteLevel(routeModule: AppRouteModule) {
9696
// Use vue-router to splice menus
9797
let router: Router | null = createRouter({
98-
routes: [(routeModule as unknown) as RouteRecordNormalized],
98+
routes: [routeModule as unknown as RouteRecordNormalized],
9999
history: createWebHashHistory(),
100100
});
101101

102102
const routes = router.getRoutes();
103103
addToChildren(routes, routeModule.children || [], routeModule);
104104
router = null;
105105

106-
routeModule.children = routeModule.children?.filter((item) => !item.children?.length);
106+
routeModule.children = routeModule.children?.map((item) => omit(item, 'children'));
107107
}
108108

109109
// Add all sub-routes to the secondary route
@@ -120,7 +120,7 @@ function addToChildren(
120120
}
121121
routeModule.children = routeModule.children || [];
122122
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);
124124
}
125125
if (child.children?.length) {
126126
addToChildren(routes, child.children, routeModule);

0 commit comments

Comments
 (0)