限制组件Angular 2中的未授权访问 [英] Restrict unauthorised access in Component Angular 2
问题描述
在用户登录之前,我必须阻止用户沿任何路线行驶。
有人可以帮助我如何在Angular 2组件路由中实现这一目标。 / p>
谢谢
您可以使用 @CanActivate
装饰器。您可以使用条件装饰要限制的组件。可以在有角文档中找到更多信息:
https://angular.io/docs/ts/latest/guide/router-deprecated.html#!#lifecycle-hooks
有一个使用名为 @CanDeactivate
的类似修饰符的示例。这是一个很好的起点,可以根据需要进行自定义。
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,
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.
这篇关于限制组件Angular 2中的未授权访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!