Angular 2:在应用程序启动时重定向到页面 [英] Angular 2 : Redirect to a page at application startup
问题描述
在Angular 2中,我的Web应用程序遇到了一个小问题.
I'm facing a little issue for my web application in Angular 2.
每次启动应用程序时,我都会检查用户是否具有访问权限. 但是我不知道如何将用户重定向到路由,这使此过程无论他身在何处都可以.
Each application launch, I would check if the user has a right of access. However I don't know how to redirect the user to the route which makes this process whatever the place where he is.
有什么想法吗?
提前谢谢!
推荐答案
有两种常见方法
- 使用 CanActivate
-
使用自定义 RouterOutlet
在此检查用户是否已通过身份验证,否则将重定向到登录路由
where you check if the user is authenticated otherwise redirect to the login route
另请参阅
-检查如果用户登录的页面在Angular 2中进行了更改
- http://www.captaincodeman.com/2016/03/31/angular2-route-security/
See also
- Check if the user logged in on any page change in Angular 2
- http://www.captaincodeman.com/2016/03/31/angular2-route-security/
这篇关于Angular 2:在应用程序启动时重定向到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!