简体   繁体   English

Angular 4路由-基于角色的访问

[英]Angular 4 Routing - Role based access

I am new to angular 4..I have a doubt regarding the routing.We have role based access to certain states.Whenever the user navigates from one state to another I have to check whether the user has access to that particular state. 我对angular 4.还是陌生的。我对路由存在疑问。我们对某些状态具有基于角色的访问权限。每当用户从一个状态导航到另一状态时,我都必须检查用户是否可以访问该特定状态。 Shall I do it using "canActivate" or shall I do it in navigationStart event method. 我应该使用“ canActivate”进行操作,还是应在navigationStart事件方法中进行操作。 Which is the best way? 最好的方法是什么? The problem of using canActivate is ,I need to specify it in all the paths. 使用canActivate的问题是,我需要在所有路径中指定它。

canActivate was made exactly for that purpose. canActivate正是为此目的而制作的。 So it should work great! 所以它应该很棒! You'll need to boil everything down to a boolean value, but other than that, canActivate is the proper solution. 您需要将所有内容都简化为布尔值,但是canActivatecanActivate是正确的解决方案。 And you shouldn't have a problem specifying it all your routes. 而且,指定所有路线都应该没有问题。

navigationStart isn't a good idea because it implies that the navigation to the new route has begun and is now in progress, which is not what you want if you are trying to keep someone from getting to a specific route. navigationStart并不是一个好主意,因为它暗示着新路线的导航已经开始并且正在进行中,如果您试图阻止某人进入特定路线,这不是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM