6

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.

2 Answers2

6
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 => {
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
3
constructor(private router: Router) {
  this.router.events.subscribe(event => {
    if (event.constructor.name === 'NavigationStart') {
      console.log(event.url);
    }
  });
}
andreasonny83
  • 1,213
  • 11
  • 19