Questions tagged [angular-route-guards]
89 questions
2
votes
1 answer
Route guard for authentication with ngrx store
I am trying to create an AuthGuard to check if an user can access a route, else, redirect to login view. I want to return an Observable from the
canActivate method. Here is what I have so far.
canActivate(route:…

Victor Mukherjee
- 10,487
- 16
- 54
- 97
2
votes
2 answers
if first user already login, how to prevent second user login on another tab
I am trying to prevent multiple simultaneous logins where if first user already login, it will prevent second user from login on another tab, i need advice on what should I need to do, based on google, i can use localstorage and authguard, and had …

hafizi hamid
- 405
- 2
- 20
- 41
2
votes
0 answers
Multiple observable in Route guard but wait for only one - Angular 5
I have a route guard in my application in which i need to check for two observables if anyone is success i should allow the route or block.
Route guard :
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
return…

Keshav1007
- 605
- 2
- 8
- 21
2
votes
1 answer
How to pause the route change in navigationStart router event
In my application I have routes exposed from packages (node modules). So i couldn't use canActivate or canDeactivate for the routes defined inside node modules.
So I started subscribing to all route change in my app component and based on condition…

Keshav1007
- 605
- 2
- 8
- 21
2
votes
1 answer
ngOnDestroy warn user before exiting
I am trying to find a way to alert user before exiting the screen. If they press "no" then it should not destroy. And if they press "ok" then carry on with destroy operations.
Does ngOnDestory has a event that happens before ngOnDestory? for example…

User1911
- 394
- 1
- 5
- 22
1
vote
2 answers
Angular Can Deactivate - Material Dropdown
I have an implementation of Angular RouteGuard CanDeactivate. It works for input fields but its not working for drop downs. I also want to display my own modal and I can't get it work correctly.
This is the Html template code:

JEuvin
- 866
- 1
- 12
- 31
1
vote
1 answer
Pass data from non sibling component to another component in Angular using a service
This is my service class
export class DataService {
public isConfirm = new Subject();
sentIsConfirm(isConfirm: boolean) {
this.isConfirm.next(isConfirm);
}
getIsConfirm(): Observable {
return this.isConfirm.asObservable();
…

Hans
- 308
- 7
- 20
1
vote
1 answer
Angular route guard doesn't render dashboard even if a cognitoUser is present
I'm trying to protect some views in my Angular app using Cognito and route guards. Basically what I'm trying to do is to check whether there is an active Cognito user session and if yes, load the page. However, even if there is a valid Cognito User,…

Pavindu
- 2,684
- 6
- 44
- 77
1
vote
1 answer
Angular 9 same route paths different components
I'm trying to resolve the correct path of a set of URLs that share the same structure. I have the path /:id/:areaId and /:id/:cityId and this is done by design for SEO reasons. When I come to implement it I need to know if :areaId exists (by making…

Carlos Torrecillas
- 4,965
- 7
- 38
- 69
1
vote
0 answers
Angular Firebase route Guard
I want to add some route guard based on Firebase auth displayName property.
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if ( firebase.auth().currentUser.displayName === 'student' ) {
return true;
} else…

Priyashan Jayasankha
- 192
- 1
- 1
- 10
1
vote
1 answer
Where to put navigation-related code in angular app?
Currently I have in my AuthGuard constructor a subsription to redux state change below. It will just redirect to original page requested after login. This is not correct place but i don't know where it should be:
auth.guard.ts:
this.subscription =…

char m
- 7,840
- 14
- 68
- 117
1
vote
1 answer
How to get get route guard to verify token after I've set it in local storage?
I'm building a simple login page with authentication using Angular and Express. I have the following:
a login component
a service that makes http calls and sets the local storage with the received jwt token
a route guard for registration page
My…

Jacob L
- 133
- 2
- 18
1
vote
2 answers
Multiple /Dashboard routes for different Roles With AuthGuard
I want my homepage load different modules for different roles
const routes: Routes = [
{
path: 'login',
component: LoginComponent,
},
{ path: '', loadChildren: './dashboard/dashboard.module#DashboardModule',…

Mubeen
- 351
- 1
- 2
- 15
1
vote
0 answers
Angular 6 use ngx-sweetalert2 in canDeactivate guards service to prevent the loss of unsaved changes on route change or page refresh
I would like to display a popup that warns a user if he/she tries to navigate away from a form which has unsaved changes. I would like to make use of ngx-sweetalert2 component since most of my app displays alerts in similar fashion. However, I…

Tejpartap Gill
- 11
- 5
1
vote
1 answer
Angular's route guard is not running within app
I've added a route with a guard on it to my app-routing.module.ts file like so:
{path: 'detail/:id', component: DetailComponent, canDeactivate: [PendingChangesGuard]},
If I try to completely leave the angular application then I see my expected…

Gargoyle
- 9,590
- 16
- 80
- 145