Questions tagged [angular-router-guards]

To find more information :

289 questions
0
votes
0 answers

angular router endless loop when navigated from from canActivate

As angular routers need static paths, I am using canActive to dynamically route my app. my main routing is as follows. import { NgModule } from "@angular/core"; import { RouterModule } from "@angular/router"; import { AuthGuard, AuthData} from…
0
votes
2 answers

How can I correctly implement an Angular Guard?

I'm implementing an AdmingGuard in angular to protect some routes. ADMIN GUARD: // --------------ADMIN GUARD // want protect routes from user who are not Admin canActivate(): boolean { // isLogged() service method: set 2 global boolean…
RoccoDen91
  • 125
  • 3
  • 9
0
votes
2 answers

CanActivate guard in angular routing without repeating "CanActivate " property

I want to use the canActivate guard in routing without repeating the canActivate: [AuthGuard], code like below import { AuthGuard } from 'src/app/core/guards/auth.guard'; const routes: Routes = [{ path: '', data: { title: 'Users' }, …
0
votes
1 answer

Angular canActivate function in guard executed twice

I'm using Angular 8, and I have a guard that opens a page in a separate tab using window.open(url) if a specific condition is met, then returns false because I don't want to leave the current page I am on. I am doing this logic in the canActivate…
0
votes
2 answers

Wait until a subscribe is called in angular

Good morning, I created an angualr app and I need to check users role in routing. I created a service "RoleGuardService" with a method canLoad that read the JWS token and check the user permission: import * as JWT from 'jwt-decode'; ... const…
0
votes
1 answer

Angular - Resolvers and Guards

in my app, I'm resolving the user from the BE after login. I would like to navigate to certain init page base on the role of the user. I have tried doing this with a can activate guard, but because guards are being calculated before resolvers, my…
0
votes
1 answer

Angular Routing to the wrong path when redirected

Angular 8.2.14 So I have a problem with my angular routing, here is the code from my routing-module: { path: "hero", component: HeroListComponent, canActivate: [AuthGuard], children: [ { path: "new", …
0
votes
3 answers

Angular Method not saving value of variable

I am creating a Route Guard in Angular; how it works is depending on if you are associated with a company; it will send you to a particular component. Unfourtnetly when running canLoad method, it does not save the value of the companieslist…
user12644181
0
votes
1 answer

Angular 9: deActivate guard and session timeout

I am having an angular app and spring boot in the backend using BasicAuth for my authentication. When the session on the server runs out I am getting a 401 and in the httpInterceptor I am then redirecting to the logout page. On some components I…
D. K.
  • 151
  • 2
  • 13
0
votes
2 answers

Using guard to protect a router with verification from server

Consider the code: import { Injectable, NgZone } from '@angular/core'; import { CanActivate, UrlTree, ActivatedRouteSnapshot } from '@angular/router'; import { Observable, throwError } from 'rxjs'; import { UsersService } from…
0
votes
1 answer

angular 9 candeactivate not working although code seems to be fine and not throwing any error

Hello Guys I am new to Angular and learning the things using the following tutorial link. For some reason the canDeactivate route guard seem to not work. Any help would be appreciated as I tried checking many things but none worked. I have the…
0
votes
0 answers

AuthGuard not being invoked on Angular 9

Im trying to implement a guard on my angular 9 project to check if the user is authenticated, but the canActivate method is not being invoked on the "sample" route that i'm trying to guard. this is my main module where i'm trying to implement the…
0
votes
1 answer

Implementing AuthGuard on login page

I am router guard so if the user has logged in, then it shouldn't allow users to go on /login. But I am able to go /login even tho I am logged in. This is authGuard export class AuthGuard implements CanActivate { constructor(private apiService:…
Shank
  • 413
  • 4
  • 15
0
votes
2 answers

CanDeactivateGuard redirect to the home page

I want when someone press browser's back button to warn him and if he press ok then i will redirect to Home Component. I use CanDeactivate Guard and i want to change the nextState of CanDeactivateGuard. I tried to change the nextState : nextState =…
Tzimpo
  • 964
  • 1
  • 9
  • 24
0
votes
2 answers

read access permissions from an array

the user's permissions come in an array, as I do to validate whether or not he has access by iterating the arrat canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { const expectedPermission =…
Jorge Nava
  • 495
  • 1
  • 5
  • 10