Commit 4c658f4868c7df6e0b8f18728c5d5ae53b04448a
1 parent
b36d9486
perf: the routeModule can ignore the layou configuration without writing
Showing
5 changed files
with
26 additions
and
10 deletions
CHANGELOG.zh_CN.md
src/router/menus/index.ts
... | ... | @@ -87,8 +87,13 @@ export async function getFlatChildrenMenus(children: Menu[]) { |
87 | 87 | function basicFilter(routes: RouteRecordNormalized[]) { |
88 | 88 | return (menu: Menu) => { |
89 | 89 | const matchRoute = routes.find((route) => { |
90 | - if (route.meta && route.meta.carryParam) { | |
91 | - return pathToRegexp(route.path).test(menu.path); | |
90 | + if (route.meta) { | |
91 | + if (route.meta.carryParam) { | |
92 | + return pathToRegexp(route.path).test(menu.path); | |
93 | + } | |
94 | + if (route.meta.ignoreAuth) { | |
95 | + return false; | |
96 | + } | |
92 | 97 | } |
93 | 98 | return route.path === menu.path; |
94 | 99 | }); | ... | ... |
src/router/types.d.ts
src/utils/helper/menuHelper.ts
... | ... | @@ -49,8 +49,12 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) { |
49 | 49 | const routeList: AppRouteRecordRaw[] = []; |
50 | 50 | cloneRouteModList.forEach((item) => { |
51 | 51 | const { layout, routes } = item; |
52 | - layout.children = routes; | |
53 | - routeList.push(layout); | |
52 | + if (layout) { | |
53 | + layout.children = routes; | |
54 | + routeList.push(layout); | |
55 | + } else { | |
56 | + routeList.push(...routes); | |
57 | + } | |
54 | 58 | }); |
55 | 59 | return treeMap(routeList, { |
56 | 60 | conversion: (node: AppRouteRecordRaw) => { | ... | ... |
src/utils/helper/routeHelper.ts
... | ... | @@ -23,18 +23,24 @@ export function genRouteModule(moduleList: AppRouteModule[]) { |
23 | 23 | for (const routeMod of moduleList) { |
24 | 24 | const routes = routeMod.routes as any; |
25 | 25 | const layout = routeMod.layout; |
26 | - let router = createRouter({ routes, history: createWebHashHistory() }); | |
26 | + const router = createRouter({ routes, history: createWebHashHistory() }); | |
27 | 27 | |
28 | - const flatList = toRaw(router.getRoutes()).filter((item) => item.children.length === 0); | |
28 | + const flatList = (toRaw(router.getRoutes()).filter( | |
29 | + (item) => item.children.length === 0 | |
30 | + ) as unknown) as AppRouteRecordRaw[]; | |
29 | 31 | try { |
30 | 32 | (router as any) = null; |
31 | 33 | } catch (error) {} |
32 | 34 | |
33 | 35 | flatList.forEach((item) => { |
34 | - item.path = `${layout.path}${item.path}`; | |
36 | + item.path = `${layout ? layout.path : ''}${item.path}`; | |
35 | 37 | }); |
36 | - layout.children = (flatList as unknown) as AppRouteRecordRaw[]; | |
37 | - ret.push(layout); | |
38 | + if (layout) { | |
39 | + layout.children = flatList; | |
40 | + ret.push(layout); | |
41 | + } else { | |
42 | + ret.push(...flatList); | |
43 | + } | |
38 | 44 | } |
39 | 45 | return ret as RouteRecordRaw[]; |
40 | 46 | } | ... | ... |