Commit 81aa229ba7dec52293367156800e3ab580c556f2
1 parent
a43d3f2f
UI: Breadcrumb component improvements
Showing
2 changed files
with
15 additions
and
4 deletions
... | ... | @@ -61,8 +61,19 @@ export class BreadcrumbComponent implements OnInit, OnDestroy { |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | + private lastChild(route: ActivatedRouteSnapshot) { | |
65 | + let child = route; | |
66 | + while (child.firstChild !== null) { | |
67 | + child = child.firstChild; | |
68 | + } | |
69 | + return child; | |
70 | + } | |
64 | 71 | |
65 | - buildBreadCrumbs(route: ActivatedRouteSnapshot, breadcrumbs: Array<BreadCrumb> = []): Array<BreadCrumb> { | |
72 | + buildBreadCrumbs(route: ActivatedRouteSnapshot, breadcrumbs: Array<BreadCrumb> = [], | |
73 | + lastChild?: ActivatedRouteSnapshot): Array<BreadCrumb> { | |
74 | + if (!lastChild) { | |
75 | + lastChild = this.lastChild(route); | |
76 | + } | |
66 | 77 | let newBreadcrumbs = breadcrumbs; |
67 | 78 | if (route.routeConfig && route.routeConfig.data) { |
68 | 79 | const breadcrumbConfig = route.routeConfig.data.breadcrumb as BreadCrumbConfig<any>; |
... | ... | @@ -72,7 +83,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy { |
72 | 83 | let ignoreTranslate; |
73 | 84 | if (breadcrumbConfig.labelFunction) { |
74 | 85 | labelFunction = () => { |
75 | - return breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue); | |
86 | + return breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue, lastChild.data); | |
76 | 87 | }; |
77 | 88 | ignoreTranslate = true; |
78 | 89 | } else { |
... | ... | @@ -96,7 +107,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy { |
96 | 107 | } |
97 | 108 | } |
98 | 109 | if (route.firstChild) { |
99 | - return this.buildBreadCrumbs(route.firstChild, newBreadcrumbs); | |
110 | + return this.buildBreadCrumbs(route.firstChild, newBreadcrumbs, lastChild); | |
100 | 111 | } |
101 | 112 | return newBreadcrumbs; |
102 | 113 | } | ... | ... |
... | ... | @@ -27,7 +27,7 @@ export interface BreadCrumb { |
27 | 27 | queryParams: Params; |
28 | 28 | } |
29 | 29 | |
30 | -export type BreadCrumbLabelFunction<C> = (route: ActivatedRouteSnapshot, translate: TranslateService, component: C) => string; | |
30 | +export type BreadCrumbLabelFunction<C> = (route: ActivatedRouteSnapshot, translate: TranslateService, component: C, data?: any) => string; | |
31 | 31 | |
32 | 32 | export interface BreadCrumbConfig<C> { |
33 | 33 | labelFunction: BreadCrumbLabelFunction<C>; | ... | ... |