angular listen for route change code example
Example: angular detect router change
import { Component } from '@angular/core';
import { Router, Event, NavigationStart, NavigationEnd, NavigationError } from '@angular/router';
@Component({
selector: 'app-root',
template: `<router-outlet></router-outlet>`
})
export class AppComponent {
constructor(private router: Router) {
this.router.events.subscribe((event: Event) => {
if (event instanceof NavigationStart) {
}
if (event instanceof NavigationEnd) {
}
if (event instanceof NavigationError) {
console.log(event.error);
}
});
}
}