Skip to content

Commit

Permalink
refactor(service): Use type predicate in rxjs filter (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonFretter authored Nov 3, 2022
1 parent 3da9791 commit 41973f7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libs/xng-breadcrumb/src/lib/breadcrumb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ export class BreadcrumbService {
this.setupBreadcrumbs(this.activatedRoute.snapshot);

this.router.events
.pipe(filter((event) => event instanceof GuardsCheckEnd))
.pipe(
filter(
(event): event is GuardsCheckEnd => event instanceof GuardsCheckEnd
)
)
.subscribe((event) => {
// activatedRoute doesn't carry data when shouldReuseRoute returns false
// use the event data with GuardsCheckEnd as workaround
// Check for shouldActivate in case where the authGuard returns false the breadcrumbs shouldn't be changed
if (event instanceof GuardsCheckEnd && event.shouldActivate) {
if (event.shouldActivate) {
this.setupBreadcrumbs(event.state.root);
}
});
Expand Down

0 comments on commit 41973f7

Please sign in to comment.