提交 | 用户 | 时间
|
820397
|
1 |
import { pathResolve } from '@/utils/routerHelper' |
H |
2 |
import type { RouteMeta } from 'vue-router' |
|
3 |
|
|
4 |
export const filterBreadcrumb = ( |
|
5 |
routes: AppRouteRecordRaw[], |
|
6 |
parentPath = '' |
|
7 |
): AppRouteRecordRaw[] => { |
|
8 |
const res: AppRouteRecordRaw[] = [] |
|
9 |
|
|
10 |
for (const route of routes) { |
|
11 |
const meta = route?.meta as RouteMeta |
|
12 |
if (meta.hidden && !meta.canTo) { |
|
13 |
continue |
|
14 |
} |
|
15 |
|
|
16 |
const data: AppRouteRecordRaw = |
|
17 |
!meta.alwaysShow && route.children?.length === 1 |
|
18 |
? { ...route.children[0], path: pathResolve(route.path, route.children[0].path) } |
|
19 |
: { ...route } |
|
20 |
|
|
21 |
data.path = pathResolve(parentPath, data.path) |
|
22 |
|
|
23 |
if (data.children) { |
|
24 |
data.children = filterBreadcrumb(data.children, data.path) |
|
25 |
} |
|
26 |
if (data) { |
|
27 |
res.push(data) |
|
28 |
} |
|
29 |
} |
|
30 |
return res |
|
31 |
} |