【发布时间】:2017-11-08 11:51:26
【问题描述】:
我已经构建了一个 loginPageGuard,如果用户已经登录,它根本不会让用户登录页面。
假设用户正在使用
http://localhost:4200/#/testUrl
并尝试前往
http://localhost:4200/#/login
LoginPageGuard 可以按我的意愿工作,并且用户保持在
http://localhost:4200/#/testUrl
问题是当用户登录并打开一个新选项卡并在浏览器中输入以下 URL 时
http://localhost:4200/#/login
应用程序不让用户登录页面,而是去
http://localhost:4200/#/
我想要的是带给用户
http://localhost:4200/#/someDesiredUrl
有什么办法可以做到这一点吗?谢谢
LoginPageGuard
@Injectable()
export class LoginPageGuard implements CanActivate {
constructor(private router: Router, private authenticationService: AuthenticationService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return this.authenticationService.isAuthorized()
.map((user:EUser)=>{
return !user.isAuthorized;
})
}
}
app.routing.ts
{
path: 'login',
canActivate:[LoginPageGuard],
component: LoginComponent
}
【问题讨论】:
标签: angular routes angular-ui-router canactivate