Reputation: 791
Is there a way in Angular to get the actual route in the NavigationEnd event instead of just the resolved url which event.url returns? I don't what the resolved params.
export class AppComponent {
constructor(private router: Router) {
this.router.events
.filter(event => event instanceof NavigationEnd)
.subscribe((event: NavigationEnd) => {
// how to get route path? Such as 'someList/:id'
});
}
}
Upvotes: 3
Views: 997
Reputation: 11525
I don't know if this is the best way but
this.router.routerState.snapshot.root.firstChild.routeConfig
will get you the route config for the current route which has the configured path,
Upvotes: 3
Reputation: 4821
You want something like this?
router.events.subscribe((event: Event) => {
console.log(event);
if (event instanceof NavigationEnd ) {
this.currentUrl = event.url;
}
});
Upvotes: -1