简体   繁体   中英

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. Shall I do it using "canActivate" or shall I do it in navigationStart event method. Which is the best way? The problem of using canActivate is ,I need to specify it in all the paths.

canActivate was made exactly for that purpose. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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