我已经为我的Angular 5.2应用程序实现了CanActivate路由器保护。如果返回true,则URL不会更改,但当返回false时,URL会更改并将路径附加到URL。在应用程序中的任何地方,我们都会更改它的路由,因此skipsLocationChange地址永远不会更改,但在这种情况下,它会更改。这基本上就是canActivate代码的样子。
canActivate(){
if(someRightsThatReturnsTrue)
return true;
else{
this.router.navigateByURL('noauthpage', {skipLocationChange: true});
return false;
}
}关于URL为什么会改变,有什么想法吗?它是不是因为不能渲染页面而“失败”的Router机械师?
发布于 2019-05-07 14:50:18
找到了一种解决方法,曾经称为
this.router.navigate(['noauthpage'], { skipLocationChange: true });你可以打电话给
this.location.replaceState('current_page');立即替换浏览器url。
https://stackoverflow.com/questions/53325237
复制相似问题