I am using router change observer in different components. I would like to have it reusable so I dont need to include this code into every component that needs it. How could I achive this?
changeObserver = null; constructor(private router: Router) { this.changeObserver = router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { if(event instanceof NavigationEnd) // change of url //-- // call some component functions - different for each component //-- }); } ngOnDestroy() { this.changeObserver.unsubscribe(); }