Reputation: 41
Here is a StackBlitz of the problem I'm facing:
https://stackblitz.com/edit/angular-ivy-aetvyf?file=src%2Fapp%2F
In AppComponent I'm subscribing to ActivatedRoute.url changes, but they only ever trigger once.
Shouldn't ActivatedRoute.url subscription emit on every route change?
I know I can use Router.events, but there you have to filter by event type and Router events don't have route segments, as ActivatedRoute.snapshot, for instance, does.
I have read all related questions, but none really answer the question.
Upvotes: 2
Views: 3635
Reputation: 1083
I have seen your code. You must subscribe on you child components i.e. a and b to detect the url changes. Currently you are adding these subscriptions on app.component. Moreover, if you want one app level solution, you have to subscribe to Router.events.
Like this :-
constructor(private ar: ActivatedRoute, private r: Router) {
this.r.events.subscribe((segs) => {
console.log('Route segments');
console.log(segs);
});
}
Upvotes: 1