Angular 2 rc3 router subscribe

In angular2 rc1, I subscribe to a route change:

this.router.changes.subscribe( () => { console.log(this.location.path()); }); 

How can I sign up for a route change in angular2 rc3? router.changes no longer exists.

+5
source share
2 answers
 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 => { 
+5
source
 constructor(private router: Router) { this.router.events.subscribe(event => { if (event.constructor.name === 'NavigationStart') { console.log(event.url); } }); } 
+3
source

All Articles