How to prevent navigation by login and registration url after login angular 2?

I am linking to prevent users from going to login and registration URL by manually typing the URL in the address bar after successfully logging in or registering. I have implemented Auth Guard for other URLs that the user cannot access without logging in. Here is my Guard Guard implementation:

@Injectable()
export class AuthGuard implements CanActivate {

  constructor(private router: Router,
    private userService: UserService) { }

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
    if (!this.userService.getLoggedInStatus()) {
      this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
      return false;
    }
    return true;
  }
}

      

And I am using it in my app.route.ts like this:

{ path:'checkout', component:CheckoutComponent,canActivate:[AuthGuard] }

      

How can I achieve the reverse for component login and registration, i.e. activate them only if the user is not logged in and disconnected after logging into the user log?

+3


source to share





All Articles