Questions tagged [angular-router-guards]

To find more information :

289 questions
1
vote
1 answer

How to get a return an observable from AngularFirestore and resolve my router guard

Question: How can my call to firestore and resolve my router guard with the payload returned from firestore? Problem: My route resolve guard does not get resolved, even though the value from firestore is being returned and is defined. import { …
1
vote
2 answers

angular - showing alert when user leaves one page (one component)

Expected behavior I have one page which contains one form, when the user want to leave this page, actually it is just one component, I want show some alert like "Do you really want to leave this page? Your changes will not be saved". Currently…
shakell
  • 351
  • 1
  • 2
  • 10
1
vote
1 answer

CanActivate route guard is not getting invoked

//guard service import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router'; import { Observable } from 'rxjs/Observable'; @Injectable() export class…
1
vote
1 answer

CanActivate guard with service call

I have a requirement where based on role I need to activate to the route. Please find code below: canActivate(): boolean { if(this.login_token) { this._Service.getUser(this.login_token).subscribe( (data) => { …
Tavish Aggarwal
  • 1,020
  • 3
  • 22
  • 51
1
vote
1 answer

CanActivateGuard and passing data into the Guard

I have an angular 4 app, and have implemented a guard to handle authentication. We have different modules which, use a factory to create what we call a ThemeService. Each module is self contained application with their own styles, and security. Each…
JoshBerke
  • 66,142
  • 25
  • 126
  • 164
1
vote
3 answers

canActivate is not working after upgrading to angular 5

I'm upgrading to angular 5 my project and I can't understand how can activate is not working anymore: //package.json: dependencies": { "@angular/animations": "~5.1.3", "@angular/cdk": "5.0.3", "@angular/common": "~5.1.3", "@angular/compiler":…
1
vote
2 answers

Return boolean in setTimeOut function in guards angular5

I want to create a route guard with canActive method and response after a few seconds. I use this: export class GuardService implements CanActivate { constructor(private router: Router, private UserInfo: UserInfoService) { } …
Leo
  • 867
  • 1
  • 15
  • 41
1
vote
1 answer

How to resolve chaning in Router of Angular4

I'm trying to chaining the router resolver This is my Router options. { path: '', component: AdminComponent, resolve: [ SessionResolve, LocaleResolve ] } I want to call SessionService(SessionResolve) and then call…
1
vote
0 answers

Angular RouterStateSnapshot params is empty when using useHash: true

I'm accessing the URL parameters of my Angular 4 app using RouterStateSnapshot and it works just fine: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { // state.root.queryParams will hold my URL parameters } the problem…
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
1
vote
0 answers

How to conditionally [de]activate child routes with same path in Angular 4?

Based on the parent path /search, would like to resolve [NavigActionResolve] and activate child routes as below. path:'search', component:SpaceComponent, resolve: { navigAction: NavigActionResolve }, children: [ { path:'', …
nsk
  • 1,413
  • 5
  • 24
  • 34
1
vote
0 answers

Router guard doesn't work

So, i trying to follow ngrx/example-app and i stacked with router guards. My guard doesn't work. import 'rxjs/add/operator/take'; import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/map'; import…
1
vote
1 answer

Angular and JWT - how does client verify token?

If I were to provide a fake JWT, I realized Angular would "accept it" as logged in as most tutorials just check if a JWT key is set in localStorage (and if it's not expired.) Is there something I'm missing about using JWT? I feel the client needs to…
Moshe
  • 2,583
  • 4
  • 27
  • 70
1
vote
0 answers

How does Angular2+ handle auth guards?

I wonder how the Angular's authorization check flow looks like. Let's say I have following authentication guards (classes implementing the CanActivate interface): asynchronous isLoggedGuard returning Observable; asynchronous isNotBannedGuard…
Daniel Kucal
  • 8,684
  • 6
  • 39
  • 64
0
votes
1 answer

Failing to test Angular functional guards using RouterTestingHarness

I am trying to test Angular functional guard with Jest as a testing framework. For mocking the Router component I am using Angular RouterTestingHarness. Here is my functional guard (I can't edit or modify my functional guard): export const guard:…
Hargun Singh
  • 544
  • 7
  • 19
0
votes
1 answer

Problem accessing RouterStateSnapshot on Angular function guards

Since the old method for Angular Guards (Class and injection token guards and resolvers) is deprecated (see angular deprecation docs) , I'm trying to update the usages of guards in my project. But I'm facing problems getting (route:…
Ghonche Yqr
  • 305
  • 1
  • 10