To find more information :
Questions tagged [angular-router-guards]
289 questions
0
votes
1 answer
Handling errors throwed in routing guards in Angular routing guards
Hello Stack community,
Is there a efficient way of handling errors throwed inside one of following:
canActivate
canActivateChild
canDeactivate
canMatch
resolve
canLoad
While Angular navigation? Simple example would be following two routes:
{
…

Tomas
- 3,269
- 3
- 29
- 48
0
votes
1 answer
Using "redirectTo" and "canMatch" in routing config to redirect users based on permissions
I'm trying to configure a set of routes where the top level URL in a module should redirect users to an alternate path in the same module based on their current permissions. I think I should be able to accomplish what I want by using the redirectTo…

joelghill
- 3
- 5
0
votes
2 answers
Angular: Prevent URL without param using a guard
I want to avoid user change the URL from /dashboard/1234-12 to /dashboard to prevent an error, so I want to redirect to /home when user type /dashboard without the id.
I have this route:
{
path: 'dashboard/:id',
component: DashboardComponent,
…

jgcarrillo
- 148
- 11
0
votes
2 answers
Authentication guard with angular
can anyone help me with this.
I am trying to implement an authentication guard for on my LogIn component.
This guard should allow users to access the dashboard only in the following conditions: If there is a session token defined in local storage…

Ami SMith
- 3
- 2
0
votes
1 answer
Angular: RouterGuards, HTTP requests and race conditions
I'm trying to create a RouterGuard in Angular that gets a response from the backend about the User's login status. The problem is that the HTTP request returns a Subscription with async concrete values.
How can I guarantee the Router will "wait" for…

João Renault
- 23
- 6
0
votes
1 answer
Angular guard runs when it should not
I have an Angular application that has two guards.
The first makes sure the user is authenticated, the second guard is to check the users role.
On some routes, the user should not be authenticated, so there are no guards. This is working fine.
On…

RobinDBL
- 9
- 2
0
votes
0 answers
Calling dispatch from route guard results in recursive calling of guard
I am using angular version 14, however I am having issues being able to update a value in the ngrx store from a route guard.
the scenario is that once a user has logged in, I call a endpoint which will tell me if their cookie is valid and if so will…

James Saunders
- 1
- 1
0
votes
0 answers
Angular Route Guard is Blocking another Rout Guard
i created Two Guards:
1st one is preventing to enter website without LogIn:
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {map, Observable} from 'rxjs';
import {LoginService} from…
0
votes
1 answer
How to Make the location.back() trigger CanDeactivate? ( in Angular 13)
I saw a similar question created about five years ago,
but my question is a little different:
I wrote a breadcrumb for whole app component, as a part of my outermost layout.
In breadcrumb, I used 'location.back()' to make a back button:

xushizhi
- 3
- 3
0
votes
1 answer
Angular - Is it possible to take the inversion of the result of a router guard?
I am writing an Angular application using Okta for authentication. I have some pages that I only want to allow a user to activate if they are not authenticated. I could not find any guards or functions in the version of the Okta package I am using,…

Will Sutton
- 47
- 7
0
votes
1 answer
Angular: whether the current route or page is protected or guard actice
I am using Angular 9 and I would like to know is there a possibility to check whether the current page is protected/guarded or not during APP_INITIALIZER phase.
I am using the APP_INITIALIZER to set some pre-configuration for the app but during this…

Phoenix404
- 898
- 1
- 14
- 29
0
votes
1 answer
How to use same route guard for different routes that differ in authorization logic
For my Angular 6 project, I have one canactivate AuthGuard to load ComponentA.
I want to know can I use the same AuthGuard for component B where it's the authorization logic is exactly opposite to component A?
Let's say the logic to authorize…

LearnToCode
- 169
- 1
- 5
- 19
0
votes
1 answer
Angular How to implement CanActivate guard with HTTP Get call
For my Angular 6 project, we want to use CanActivate guard to check authorization.
To implement this, I need to call getSummary() http get call from app.service and perform some logic from its response to provide authorization.
The Logic goes as…

LearnToCode
- 169
- 1
- 5
- 19
0
votes
0 answers
CanDeactivate Guard does not return false after calling AngularFireAuth signOut() function - Angular 13
I have a dashboard page where I implemented a CanDeactivate guard to avoid logged users leaving the page before logging out. It works. But when I push my Logout button, the guard still returns true, but it should return false since there is no user…

Luiz Federico
- 21
- 1
- 4
0
votes
1 answer
How can I guard routes in Angular?
Currently, after logging in I'm able to get the JWT to the frontend. My app currently has a logging page as the landing page and as soon as the user logins the route checks for authentication to redirect to the guarded home path.
My first intuition…

Diego Burela
- 5
- 3