In angular2 rc1 I subscribe for a change of route:
this.router.changes.subscribe(
() => {
console.log(this.location.path());
});
How I can subscribe to change route in angular2 rc3? router.changes already doesn't exists.
constructor(router:Router) {
router.events.subscribe(event:Event => {
if(event instanceof NavigationStart) {
}
// NavigationEnd
// NavigationCancel
// NavigationError
// RoutesRecognized
}
}
or
constructor(router:Router) {
router.events.forEach(event:Event => {
constructor(private router: Router) {
this.router.events.subscribe(event => {
if (event.constructor.name === 'NavigationStart') {
console.log(event.url);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With