fix: Sidans titel ändras nu korrekt när man går tillbaka till startsidan. (TV-643)
Squashed commit of the following: commit b70383f449eb2e17e0da2e479316c821cdf4bb85 Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se> Date: Wed Sep 22 15:04:38 2021 +0200 fix: Flyttade titlesättning från layout.component till app.component. Krävde mer logik för att hitta vilken route man är på. (TV-643)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||
import { filter, map, mergeMap, switchMap } from 'rxjs/operators';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'msfa-root',
|
||||
@@ -9,7 +12,30 @@ import { environment } from '@msfa-environment';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AppComponent {
|
||||
constructor(@Inject(DOCUMENT) private document: Document) {
|
||||
constructor(
|
||||
@Inject(DOCUMENT) private document: Document,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private titleService: Title
|
||||
) {
|
||||
this.document.body.dataset.version = environment.version;
|
||||
|
||||
this.router.events
|
||||
.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
map(() => traverseUntilNoChildRoute(this.activatedRoute)),
|
||||
switchMap((route: ActivatedRoute) => route.data)
|
||||
)
|
||||
.subscribe((routeData: { [title: string]: string }) => {
|
||||
const pageTitle = routeData.title;
|
||||
this.titleService.setTitle(`${pageTitle ? `${pageTitle} - ` : ''}Mina sidor för fristående aktörer`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function traverseUntilNoChildRoute(route: ActivatedRoute): ActivatedRoute {
|
||||
while (route.firstChild) {
|
||||
route = route.firstChild;
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user