To find more information :
Questions tagged [angular-router-guards]
289 questions
2
votes
2 answers
Returning an Observable from canActivate method and redirect on false
I have been searching for a solution with no luck. I need to call the server if a user is authorized and i need canActivate method to wait for the result for that call. But i can`t seem to put pieces together. Below is my code, my question is in the…

rematnarab
- 1,277
- 4
- 22
- 42
2
votes
0 answers
Angular 4 - Guard Causing Error Cannot read property 'create' of undefined
i've created a Guard (LoggedInGuard) that i defined in an AuthModule Which i import in my AppModule.
i've also created a DashboardModule that in his routing module it use the the LoggedInGuard from the AuthModule
when using the LoggedInGuard in…

Hen Bar Levi
- 111
- 7
2
votes
1 answer
Angular Route Guard CanActivate stops routing
I am trying to check weather the user has already selected a company to login. If they select then they see those company employees. Otherwise, we will redirect to login page.
I have used Angular Route Guard to do this. But its not continuing the…

Developer
- 487
- 9
- 28
2
votes
2 answers
angular dependency injection of one service into another for route guard
In my angular app I have two services, one deals with the http layer, and the other is simply a route guard to implement the canActivate method related to the status of the first service. For example:
backend.service:
@Injectable()
export class…

Westwick
- 2,367
- 3
- 28
- 51
2
votes
2 answers
How to show modal confirmation in CanDeactivate in Angular2 application?
I have an Angular2 application. One of its components implements CanDeactivate interface to confirm user's navigation away from the page. Here is the implementation of the route guard:
export class DeactivateGuard implements…

myroslav
- 1,670
- 1
- 19
- 40
2
votes
1 answer
Routing to a specific page within a lazy-loaded module in angular 2+
I have the following in my main app router:
{ path: 'users', loadChildren: 'app/modules/users/users.module#UsersModule', canLoad: [AuthGuard] }
When the user goes to http://localhost:4200/users/1234 to see their profile, I try to save the full url…

Sammy
- 3,395
- 7
- 49
- 95
2
votes
0 answers
Angular2 CanDeactivate with directive instead of component
Is it possible to use CanDeactivate with a directive instead of a component?
My implementation is shown below, but doesn't work:
class CanDeactivateTeam implements CanDeactivate {
canDeactivate(
directive:…

raneshu
- 363
- 2
- 16
- 46
2
votes
1 answer
Configure Angular router guard
Is there any way to configure a canActivate guard used in Angular's router?
Having this SessionGuard:
@Injectable()
export class SessionGuard implements CanActivate {
public requireLeagues: boolean = true;
constructor(private authService:…

Javier Marín
- 2,166
- 3
- 21
- 40
1
vote
0 answers
Getting NullInjectorError while using inject for guard (since CanActivate is deprecated)
I was using CanActivate, but I recently migrated to Angular 16 and since it is deprecated, I tried to use inject() as guided by the official documentation.
This is how my routing component looks like:
const routes: Routes = [
{
path: '',
…

Rahul Roy
- 275
- 1
- 10
1
vote
0 answers
Logout is not working properly - angular-oauth-oidc
I'm using the angular-oauth-oidc library to manage authentication in an angular app. I'm also using this sample as the base for my work: https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards
When i start the project and try…

Waray Mohamed Amine
- 361
- 4
- 16
1
vote
2 answers
Router doesn't redirect by guard
I have an angular app with Angular 15. App-routing module somehow doesn't redirect, when a guard returns the UrlTree.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {…

Maestro
- 43
- 1
- 6
1
vote
1 answer
Angular 15: Empty ActivatedRoute params in Functional Route Guards
I use new functional guards like:
export function AuthGuard() {
const route = inject(ActivatedRoute);
const authService = inject(AuthService);
return authService.state$.subscribe((user) => {
return user.uuid ===…

Konstantin Grig
- 60
- 7
1
vote
1 answer
Activate Angular guard for both parent and child nested module routes
I'm working with Nested Module Structure and having some difficulty to implement guard.
Right Now I have to use canActivate on parent module route and canActivateChild on every child module route.
I want a solution where I will just put guard on…

M Nouman
- 437
- 1
- 5
- 22
1
vote
1 answer
CanDeactivate Guard not hiding URL in browser window on cancelling navigation
I am using the skipLocationChange property with true value so I can hide the URL in the browser. It is working fine. But for one of my features, I am using CanDeactivate guard so I can warn the user to save changes before leaving the current page. I…

Aakash Giri
- 53
- 1
- 8
1
vote
0 answers
How to redirect to the url user initially tried after authenticating with aws cognito in angular app
kindly help me on this scenario,
I am working with an angular application which has aws cognito authentication, here the user will access the app using a dynamic link with query string from an email.
Since the app has not in authenticated state and…

Alvin R
- 29
- 7