I have implemented the CanActivate router guard for my Angular 5.2 app. If it returns true the URL does not change, but when it returns false, the URL changes and appends the path to the URL. Everywhere in the app that we change the route it skipsLocationChange so the URL never changes, but it does in this case. This is what the canActivate code looks like basically.
canActivate(){
if(someRightsThatReturnsTrue)
return true;
else{
this.router.navigateByURL('noauthpage', {skipLocationChange: true});
return false;
}
}
Any ideas on why the URL is changing? Is it an Router mechanic because it can't render the page and is 'failing'?
found a workaround with it, once called the
this.router.navigate(['noauthpage'], { skipLocationChange: true });
you may call
this.location.replaceState('current_page');
to replace the browser url immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With