Currently in Angular 4, if I'm trying to verify this route is working:
/my/long/route
If I go to it directly and it throws an error, the Router will update the url to /, since no valid routes have loaded. If I navigate to the error throwing route in the application, the url is set to the last route that worked.
Is there a way I can keep the url set on the failed route url? From an error logging perspective, it would be nice if I could just use the actual url the user was on opposed to fishing for it in the router events, and for local debugging it would be nice to be able to refresh the page opposed to needing to navigate back to it every time.
Based on the source code:
I don't really see a way of getting around the issue.
For now I'm just going to do this (which has it's own set of problems):
this.router.events.subscribe(event => {
if (event instanceof NavigationError) {
this.routeFailed = true;
setTimeout(() => this.location.replaceState(event.url));
} else {
this.routeFailed = false;
}
});