简体   繁体   English

在Component Angular 2中限制未经授权的访问

[英]Restrict unauthorised access in Component Angular 2

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. 有人可以帮助我如何在Angular 2组件路由中实现这一点。

Thanks, 谢谢,

You can use the @CanActivate decorator that angular2 provides. 您可以使用angular2提供的@CanActivate装饰器。 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 https://angular.io/docs/ts/latest/guide/router-deprecated.html#!#lifecycle-hooks

It has an example using a similar decorator called @CanDeactivate . 它有一个使用类似装饰器@CanDeactivate This is a good starting point, customize it to your needs. 这是一个很好的起点,可根据您的需求进行定制。

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

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