Reputation: 2611
i know how to detect route changes in each component, so i have to put the same code in each one to get this changes
but my purpose is to detect route changes in general way, is there any possibility to do this ?
Upvotes: 2
Views: 1756
Reputation: 10824
You need to put your route detection logic in the top component, which has the topmost/first <router-outlet>
.
In my case this would be AppComponent
.html
<router-outlet></router-outlet>
.ts
export class AppComponent {
constructor(
private router: Router
) {
router.events.subscribe(event => console.log(event));
}
}
Upvotes: 2