Browse Source

fix(admin-ui): Prevent breadcrumbs flash on route change

Michael Bromley 7 years ago
parent
commit
3d278e05a7

+ 6 - 6
admin-ui/src/app/core/components/breadcrumb/breadcrumb.component.ts

@@ -2,7 +2,7 @@ import { Component, OnDestroy } from '@angular/core';
 import { ActivatedRoute, Data, NavigationEnd, Params, PRIMARY_OUTLET, Router } from '@angular/router';
 import { flatten } from 'lodash';
 import { combineLatest as observableCombineLatest, Observable, of as observableOf, Subject } from 'rxjs';
-import { filter, map, takeUntil } from 'rxjs/operators';
+import { filter, map, startWith, switchMap, takeUntil } from 'rxjs/operators';
 import { DataService } from '../../../data/providers/data.service';
 
 export type BreadcrumbString = string;
@@ -36,12 +36,12 @@ export class BreadcrumbComponent implements OnDestroy {
     constructor(private router: Router,
                 private route: ActivatedRoute,
                 private dataService: DataService) {
-        this.router.events.pipe(
+        this.breadcrumbs$ = this.router.events.pipe(
             filter(event => event instanceof NavigationEnd),
-            takeUntil(this.destroy$))
-            .subscribe(event => {
-                this.breadcrumbs$ = this.generateBreadcrumbs(this.route.root);
-            });
+            takeUntil(this.destroy$),
+            startWith(true),
+            switchMap(() => this.generateBreadcrumbs(this.route.root)),
+        );
     }
 
     ngOnDestroy(): void {