Restrict unauthorised access in Component Angular 2

Deadly 提交于 2019-12-23 17:26:47

问题


I have to prevent user to move on any route until user is logged in.

Can somebody help me how can we achieve this in Angular 2 Component Routing.

Thanks,


回答1:


You can use the @CanActivate decorator that angular2 provides. You decorate the component that you want to restrict with a condition. More info can be found in the angular docs:

https://angular.io/docs/ts/latest/guide/router-deprecated.html#!#lifecycle-hooks

It has an example using a similar decorator called @CanDeactivate. This is a good starting point, customize it to your needs.



来源:https://stackoverflow.com/questions/35924577/restrict-unauthorised-access-in-component-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!