Questions tagged [angular-guards]
123 questions
2
votes
0 answers
angular 2 candeactivate not working with child components
I have form in child components and i put child component under parent-component form. I have implemented canDeactivate which is not working for child component.
export const routes: Routes = [
{path: '', component: AppComponent,children:[
…

Siddu hadapad
- 3,023
- 5
- 15
- 26
2
votes
0 answers
How to handle CanActivate on browser refresh Angular 4
I have an application where I need to secure routes based on roles to a particular user. I have windows authentication in my app, so there is so separate login page for this, so I am calling login method directly from app.component.ts. Everything…

thecrusader
- 301
- 6
- 18
2
votes
2 answers
Angular 2+: Accessing Route in Transit Query Params and not the Current Active Route
Problem:
I am trying to access the query params that a route guard is checking, and not the current url snapshot query params.
ActivatedRoute only shows the current route status they are on, and not the one that is in transit. So if I am on page…

Chris Cooley
- 125
- 1
- 10
2
votes
1 answer
Angular + ngrx: Async canActive Guard must be cancelled from somewhere else
As the title says: Is there a way to tell the router to cancel its current navigation?
Here's the situation:
A route guard dispatches an action.
An effect performs an async call based on that action.
Upon completion, the async call will dispatch a…

Jem
- 6,226
- 14
- 56
- 74
1
vote
1 answer
Testing a functional Angular Routing guard
Hello since the class guards are deprecated, I moved mine to a functional, but my test broke and I'm really confused of the injectable service of keycloak and the parameters of the guard.
Here is the Guard:
export const authGuard: CanActivateFn =…

DevDuke
- 45
- 6
1
vote
2 answers
CanActivate is deprecated. How to refactor?
Angular - CanActivate is deprecated. How to refactor?
I found the documentation on the site very scarce and I am not able to adapt it to use CanActivateFn
How to suit to use CanActivateFn?
Follow my code:
AuthGuard:
export class AuthGuard implements…

Leandro
- 91
- 1
- 9
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
2 answers
Angular CanActivate guard wait for api response and not calling api everytime
I have an observable to check if the user is loggedIn or not. I set that observable from auth api which is called from appComponent when application starts.
export class AppComponent implements OnInit {
loggedIn$: Observable

Bhavesh
- 819
- 1
- 17
- 31
1
vote
2 answers
Angular 12: canActivate Guard not working on page refresh
My canActivate guard works like this: if the current (fire auth) user has a user profile, then he can access the route. Otherwise, I route him to the profile creation page.
This works perfectly fine, unless I refresh the page!
Guard:
export class…

kapafo
- 11
- 2
1
vote
1 answer
CanActivate requesting a stream after NavigationEnd
I'm trying to build a SubscriptionGuard in Angular.
This Guard should check whether the user has paid or not for the subscription.
I'm having a weird issue. I'll show the code and will explain this after.
subscription.guard.ts
import { Injectable…

Pietro Lungarini
- 103
- 2
- 12
1
vote
0 answers
Angular 9: Guard which calls API to check if session did not expire
On some pages in my Angular app, I want to validate the session is not expired.
I have token in local storage, so in AuthService I have:
isUserAuthenticated(): Observable {
const token = localStorage.getItem('token');
if(token) {
…

Filip Witkowski
- 795
- 3
- 14
- 24
1
vote
2 answers
How to manage login session in Angular with Spring boot project?
I am developing an Angular application with Spring boot.
I have developed a login page that takes username and password as input.
A web service which authenticates the user from the backend and sends a response with success and failure.
And a…

Swapnil Hadge
- 59
- 2
- 11
1
vote
2 answers
how to show just the components of the current user by role in angular
Hello every one i have a dashboard that has a menu of all the components :
i want when i m logged in with the role admin i want to display all the components
and if i m logged with the responsable role i want to show just the commandes component
i…

II-ZIAD- II
- 15
- 8
1
vote
0 answers
How to trigger router Guards without changing page
I am using Angular 9 (Ivy). I want to trigger router Guards without actually changing the page. With the current abilities of Angular, how can I accomplish this?
This following is example code that does not work but should give an idea of what I am…

ebakunin
- 3,621
- 7
- 30
- 49
1
vote
1 answer
Angular 9 - Guard: canActivate wait until specific condition is met
I've the following code
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable {
this.userStore$ = this.store.pipe(select('userStore'));
return this.userStore$.pipe(
map( res => {
if(res) return true…

user1088417
- 55
- 2
- 9