Is there a way to trigger an action only on specific NavigationEnd
router events, excluding when navigating between child routes or on a particular route?
This is a snippet from my app.routing.ts
:
// other route configurations...
{ path: 'scrapers/:version', component: SingleScraperComponent, children: [
{ path: '', redirectTo: 'statistics', pathMatch: 'full' },
{ path: 'statistics', component: ScraperStatisticComponent },
{ path: 'targets', component: ScraperTargetsComponent },
]},
// other route configurations...
In the SingleScraperComponent
, I have subscribed to Router
events like this:
// component code
ngOnInit(): void {
this._router.events.filter(event => event instanceof NavigationEnd).takeWhile(() => this.isAlive).subscribe(
(event: NavigationEnd) => {
console.log(event);
if (event.url.indexOf('site-preview') === -1) {
this._site.resetQuery();
}
}
);
}
// component code
I am considering using OnDestroy
, but I would need to determine the next route after destroying SingleScraperComponent
.