To find more information :
Questions tagged [angular-router-guards]
289 questions
4
votes
1 answer
Angular Guards: Prevent manually accessing a URL
We have several routes in our app which are not supposed to be navigated by the user by directly entering their URLs into the browser’s address bar.
Instead we only want to make them accessible when we programmatically navigate using…

qqilihq
- 10,794
- 7
- 48
- 89
4
votes
3 answers
How to combine angular fire guards?
The AngularFire auth guard doc shows different ways to allow authentication.
Only admin users:
const editorOnly = pipe(customClaims, map(claims => claims.role === "editor"));
Self only:
const onlyAllowSelf = (next) => map(user => !!user &&…

f.khantsis
- 3,256
- 5
- 50
- 67
4
votes
4 answers
Angular 6: Convert eager loading to lazy loading
I have a complete angular app that uses eager loading.
I want to convert it to lazy loading, but because I have guard on all of my routes and all of them are sub routes to one main route that is guarded, I don't know if it's possible to do it and…

Ofir Sasson
- 673
- 4
- 16
- 39
4
votes
2 answers
AngularFireAuth redirect issue with angular routing guard
Dear stackoverflow community,
i have the following issue. I try to use FirebaseAuthentication together with Angular7 and im trying to secure routes with guards so only logged in users can for example visit the /profile url.
My login…

Jan Kreischer
- 679
- 3
- 8
- 21
4
votes
1 answer
Angular CanDeactivate Router Guard with an Observable Subscribed Value
I've been trying to write a canDeactivate guard to check a saving state from an observable stream and work accordingly.
My service goes as this
import { Injectable } from '@angular/core';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import {…

Saiyaff Farouk
- 5,103
- 4
- 24
- 38
4
votes
1 answer
Angular 4 resolve guard redirect without changing URL?
I want to display a 404 page/component if my resolve guard fails, but I do not want the URL of the browser to change.
I can navigate without changing the URL in the resolve as described here by doing:
this.router.navigate(['/404'], {…

tam5
- 3,197
- 5
- 24
- 45
4
votes
1 answer
this.router.navigate in Guard blocks routes in future
I have set up two guards in Angular 4 -- one that redirects users to the login page when they try to reach a protected route, and one that redirects users to the welcome page from 'Home' if they haven't been there yet.
The guards themselves work…

tcmoore
- 1,129
- 1
- 12
- 29
3
votes
6 answers
How to use CanActivateFn in Angular 16 via constructor dependency injection
How can I make use of the latest CanActivateFn in Angular 16 with DI?
The recent Angular 16 uses a function, not a class, for the canactivate functionality.
This is my code below. How can I add my DI's that would normally be in the constructor in…

joseph chikeme
- 184
- 1
- 12
3
votes
1 answer
The guard does not work the second time in angular 11
I am configuring a guard for my angular app and it happens that when I run the application and log in the first time it works fine, but I configure an error interceptor where I have a condition that when the user receives a 401 error from the api it…

Deybi Tabora Paz
- 171
- 3
- 11
3
votes
3 answers
When using an Angular route Guard: 'Observable' is not assignable to type > 'Observable'
I'm new to Angular.
How can I solve this problem?
I have installed Angular CLI: 11.0.7 and Node: 12.18.4
I have installed an Angular route guard:
ng g guard auth --skip-tests
The error:
Error: src/app/_guards/auth.guard.ts:15:5 - error TS2322:…

x19
- 8,277
- 15
- 68
- 126
3
votes
2 answers
Angular 9 Router - CanActivate not working with redirects
The use case: I want to redirect logged in users to /dashboard, and non-logged in users to /landing.
First take:
{
path: '**',
redirectTo: '/dashboard',
canActivate: [AuthGuard],
},
{
path: '**',
redirectTo: '/landing'
…

Ákos Vandra-Meyer
- 1,890
- 1
- 23
- 40
3
votes
1 answer
Set default query params while routing
I've the following route config:
const routes: Routes = [
// another routes
{ component: UsersListComponent, path: 'users' }
];
I want to "automatically" include some default QUERY parameters when something route to this.
E.g.:
The route…

dev_054
- 3,448
- 8
- 29
- 56
3
votes
2 answers
Angular 6 role based routing on root url
I'm trying to implement role based routing for my root url. For example, when user logged in, I can redirect him to User's dashboard page from login.component. Same applied for admin, also redirect to admin dashboard page through login. But how to…

hxdef
- 393
- 2
- 6
- 15
3
votes
2 answers
Angular redirect to dashboard if user is logged in
I am using Angular v6, I have implement redirect from dashboard to login page if user is not logged in.
I'm confused between the two options:
Add a login guard file to check login status and redirect to dashboard
Detect route changing event,…

dangquang1020
- 496
- 3
- 7
- 23
3
votes
1 answer
Turn off Angular 5 routing
We are working on a SPA. In some situations, one part of it is rendered into another application (as part of the markup).
In this situations, we don't want routing in our application because we could possibly "steal" it from the other…

Daniel
- 168
- 1
- 14