I have built a loginPageGuard which simply not letting user lo login page if it is already logged in.
Lets say user is on
http://localhost:4200/#/testUrl
and tries to go to
http://localhost:4200/#/login
LoginPageGuard works as i want it to and user stays on
http://localhost:4200/#/testUrl
The problem is when user is logged in and opens a new tab and enter following URL in browser
http://localhost:4200/#/login
App doesn`t let the user to login page but goes to
http://localhost:4200/#/
What i want is to take to user to
http://localhost:4200/#/someDesiredUrl
Is there any way to achieve this ? Thanks
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
}