Questions tagged [angular-route-guards]
89 questions
13
votes
3 answers
CanActivate guards on child routes run before parent Resolve finish
I'm trying to resolve data before navigating to children routes as i have to use that data in children guard. The issue is parent resolver, resolves data after the child guard is fired. Resolver takes long time to resolve data
// app.module.ts
const…

Asad Shah
- 771
- 2
- 8
- 22
9
votes
1 answer
Observable> to Observable
RxJS beginner here. I am using Angular 6, and am trying to figure out how to get Observable from Observable>. I'm not sure if this is even valid and I'm struggling to understand it conceptually, however it seems like a simple…

Web Dev
- 2,677
- 2
- 30
- 41
8
votes
3 answers
Angular: how to call router.navigate() relative to target route in a RouteGuard?
I have an existing project developed with Angular 4. I need to control the access to a particular route based on user-rights. The simplified route configuration looks like this:
[
{ path: '', redirectTo: '/myApp/home(secondary:xyz)', pathMatch:…

Faruq
- 1,361
- 1
- 11
- 23
4
votes
2 answers
Conditional rendering of components in Angular child router outlet
I am trying to find a way to conditionally render components in the router-outlet of a child route, based on the user's role.
For example, I have a DashboardComponent, which contains a router-outlet. I want the component that is rendered in child…

lordchancellor
- 3,847
- 4
- 26
- 26
4
votes
2 answers
can activate guard and using observables with in them angular 5
I am using a route guard that implements canActivate
I have placed a bunch of console logs in the code to understand where it is failing.
what happens is if I navigate to the protected route. The navigation fails because the guard fails to return a…
user9487981
4
votes
1 answer
Angular Route Guards: Or vs. And
I'm working on securing the front-end of my Angular application using route guards. In working with them in the past and researching online, adding multiple guards to a route requires all of them to return true to allow access.
But what if I want…

Nathan Foss
- 595
- 1
- 9
- 34
3
votes
1 answer
TypeError: Cannot read property 'canDeactivate' of null in IONIC 5
I am unable to implement canDeactivate guard in Ionic 5. Following are my code.
model.ts
export interface isDeactivatable {
canDeactivate: () => Observable | Promise | boolean;
}
leave-page.guard.ts
export class…

Tapas Mukherjee
- 2,088
- 1
- 27
- 66
3
votes
0 answers
CanDeactivate is not working with sibling modules using Observable
I'm implementing canDeactivate guard in my component using primeng confirmation service, creating an observable for user answer of the prompt.
The problem is that when I try to navigate to sibling route and click yes to the prompt, the router does…

Petar Sabev
- 66
- 1
- 7
3
votes
2 answers
Angular get data from kerberos authentication
I have an angular application with a backend. The authentication is managed by the browser with Kerberos before the app has started. The response contains a JWT with roles in it.
My approach is an extra HTTP call to the server when the app is…

ochs.tobi
- 3,214
- 7
- 31
- 52
3
votes
1 answer
How to apply routing guards to feature module routing modules?
So, I'm building an Angular 4 app that I want all routes to be protected (except for the login route of course). I'm trying to use feature modules and feature module routing. So, imagine something like this:
import { NgModule } from…

Iraklis Alexopoulos
- 909
- 2
- 14
- 27
2
votes
2 answers
Angular routing: Conditional route with library import
TL;DR
How can I have a conditional route with conditional import of the corresponding Angular library during build time, depending on a feature flag in the environment file?
Background
I'm having a route configuration that lazy loads an Angular…

dude
- 5,678
- 11
- 54
- 81
2
votes
1 answer
Route multiple modules to the same path
I'm trying to make a role based routing system where app-routing module has multiple modules routing to the same route.
Eg.
const routes: CustomRoutes = [
{ path: 'login', component: LoginFormComponent },
{
path: '',
canActivate:…

JudasMoses
- 378
- 4
- 22
2
votes
0 answers
Prevent navigation in ngDestroy angular
I want to prevent the user from navigating away from the current page if the form is dirty. While this works with CanDeactivate guard, the problem is when I try to move on to another child component of the same parent, without a route change. The…

user5663970
- 119
- 2
- 13
2
votes
1 answer
Do Angular routes subscribe to the observable a RouteGuards returns?
I'm a little confused by how Angular routes treat the observables that a guard returns. Take the following route guard:
export class AuthenticationGuard implements CanActivate {
constructor(private sessionQuery: SessionQuery, private router:…

Peter Nixey
- 16,187
- 14
- 79
- 133
2
votes
1 answer
How to access route params in route guard clause in Angular 7?
I have an Angular 7 app in which I have a route like this
{ path : 'forgot-password/:resetHash/:email',
component : ForgotPasswordComponent,
canActivate : [ForgotPasswordPageGuard]},
Now I tried to access this route's params in it's…

Fahad Hassan
- 781
- 10
- 20