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 { DOCUMENT } from '@angular/common';
|
||||||
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
||||||
import { environment } from '@msfa-environment';
|
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({
|
@Component({
|
||||||
selector: 'msfa-root',
|
selector: 'msfa-root',
|
||||||
@@ -9,7 +12,30 @@ import { environment } from '@msfa-environment';
|
|||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
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.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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,17 +40,13 @@ export class LayoutComponent extends UnsubscribeDirective {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private activatedRoute: ActivatedRoute,
|
private activatedRoute: ActivatedRoute,
|
||||||
private authenticationService: AuthenticationService,
|
private authenticationService: AuthenticationService,
|
||||||
private userService: UserService,
|
private userService: UserService
|
||||||
private titleService: Title
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
super.unsubscribeOnDestroy(
|
super.unsubscribeOnDestroy(
|
||||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => {
|
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => {
|
||||||
const pageTitle = this.activatedRoute?.snapshot?.data?.title as string;
|
|
||||||
const urlTree = this.router.parseUrl(this.router.url);
|
const urlTree = this.router.parseUrl(this.router.url);
|
||||||
|
|
||||||
this.titleService.setTitle(`${pageTitle ? `${pageTitle} - ` : ''}Mina sidor för fristående aktörer`);
|
|
||||||
|
|
||||||
if (urlTree.queryParams.code) {
|
if (urlTree.queryParams.code) {
|
||||||
void this.router.navigate([], {
|
void this.router.navigate([], {
|
||||||
relativeTo: this.activatedRoute,
|
relativeTo: this.activatedRoute,
|
||||||
|
|||||||
Reference in New Issue
Block a user