简体   繁体   中英

Authorization in Angular2

I'm new in Angular2. I would much appreciate if there is somebody who can help me to sort my problem out. I would like to implement an authorization mechanism per route (as it is at this link , but with the new RouterOutlet).

I've tried to extend the RouterOutlet and I've received the following error: 'Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'HomeComponent''

The solution in the blog post you mentioned is too complicated and uses deprecated API. An simpler solution is to protect the route without the need to create additional router outlet. Use router guards to allow to navigate to the route if the user was authenticated. I blogged about using router guards here: https://yakovfain.com/2016/07/20/angular-2-guarding-routes/

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