0

In Beta 17 the URL was passed to the subscriber like so

this.router.subscribe(function(url){ if( typeof url !== "undefined" ) { if( url.length > 0 ) { console.log('Handle router changes /' + url); } } }.bind(this)); 

In rc 1 I believe you have to subscribe to the router.changes emitter however no parameters are passed? this.router.changes.subscribe(function(url){ // url is always null }.bind(this)); Is there some other way to subscribe to router changes in rc1

1 Answer 1

1

I also ran into this problem. From looking at the router code this is what is returned from the router.changes() observable:

this._changes.emit(null); 

In other words, .changes() fires an event to let you know the route changed but it doesn't give you the value it just emits null, hopefully this will be updated in future releases. As a work around for now, the way I have done it is to subscribe to the changes observable and then check the location.path() to get the current value:

this.router.changes.subscribe(() => this.state = this.location.path()); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I am already doing that. I need to handle root "/" and load the default component because rc1 does not seem to have functioning redirectTo option. I fail to see why they cant pass the urlTree in the event, Its such a simple fix. The current release of the new router is very frustrating.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.