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.

1

2 Answers 2

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 => { 
Sign up to request clarification or add additional context in comments.

3 Comments

Is if(event is NavigationStart) sudo code? no such thing as 'is' in Javascript is there? I can't figure out a way to check for a specific event like you're showing in the example.
Use if(event instanceof NavigationStart) instead of is
Thanks @KrishnanunniJeevan. Sorry, mixed some Dart into the code - fixed.
3
constructor(private router: Router) { this.router.events.subscribe(event => { if (event.constructor.name === 'NavigationStart') { console.log(event.url); } }); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.