To find more information :
Questions tagged [angular-router-guards]
289 questions
56
votes
4 answers
How to elegantly get full url from the ActivatedRouteSnapshot?
In some of my Angular route guards, I want to set up the "next" path, to redirect to after successful login.
So, the ordinary guard canActivate function signature looks like this:
public canActivate(route: ActivatedRouteSnapshot):…

Radosław Roszkowiak
- 6,381
- 3
- 15
- 27
16
votes
4 answers
Angular 4 Multiple Guards - Execution Sequence
I have 2 guards, AuthGuard and AccessGuard in the application.
AuthGuard protects all the pages as the name suggests and stores the session object in the GlobalService and AccessGuard depends on the some access data in session object stored by…

Akul Narang
- 331
- 1
- 2
- 10
14
votes
4 answers
Angular 5/6: protect route (route guard) without redirecting to error route
I have a bit of a pickle.
I am using Route guard (implementing CanActivate interface) to check if user is granted access to particular route:
const routes: Routes = [
{
path: '',
component: DashboardViewComponent
},
{
…

Ivan Hušnjak
- 3,493
- 3
- 20
- 30
12
votes
1 answer
Routes Guards causing wrong Route Navigation behavior
I'm having an issue trying to navigate through different routes.
I have two different route modules.
app.routes.ts:
Containing only LoginPage:
export const routes: Routes = [
{
path: 'login',
component: LoginPageComponent,
canActivate:…

AndreaM16
- 3,917
- 4
- 35
- 74
11
votes
2 answers
lazy-loaded child route loads twice in Angular
I am confronted with the following issue: the personal section which is protected via an AuthGuard Service is loaded twice when I navigate to it or by browser refresh. Second time it strips away the query parameters of the URL if I provide any. Here…

ama
- 1,525
- 1
- 16
- 34
10
votes
4 answers
Execute Multiple Asynchronous Route Guards in Order
I know angular route guards execute in the specified order when the canActivate function returns a simple boolean, however, what if the guards return type Observable or Promise?
Example in route:
{
path: 'confirm',
…

Kevin LeStarge
- 8,142
- 4
- 21
- 34
9
votes
2 answers
Wait for http inside Guard on Angular 5
I'm using a Guard on an Angular application to resolve initial critical data. On the version 4 of Angular I was duing it like this:
// app.routing.ts
routing = [{
path: '', component: AppComponent, canActivate: [ResolveGuard],
}];
//…

celsomtrindade
- 4,501
- 18
- 61
- 116
9
votes
1 answer
Router infinite loop with second canActivate guard on lazy-loaded modules
I have an angular 4.3.6 application with lazy-loaded modules. Here is a partial root router:
const routes: Routes = [
{ path: '', redirectTo: 'fleet', pathMatch: 'full' },
{
path: '',
component: AppComponent,
canActivate:…

msanford
- 11,803
- 11
- 66
- 93
9
votes
0 answers
router.navigate and router.navigateByUrl not working
I am saving the requested Url in the localstorage, redirect to an identity-server, this one redirects back to my root url, and then i want to navigate to the previously saved url.
I am saving the url in a guard:
canActivate(
next:…

Markus Kollers
- 3,508
- 1
- 13
- 17
8
votes
4 answers
Cypress with Azure AD (MSAL)
I'm new to both Cypress and Azure AD, but I've been following the steps described here to create Cypress tests on an existing Angular app that uses Azure AD. It mentions that they are using ADAL, but our app uses MSAL, which it says should be…

Michael McMullin
- 1,450
- 1
- 14
- 25
8
votes
1 answer
Issue with canDeactivate : "Type 'CanDeactivate' is not generic"
I am trying to set up a simple canDeactivate guard in Angular 7, and I have tried code from a number of online tutorials, but they all yield the same error:
"Type 'CanDeactivate' is not generic."
What am I doing wrong? I can't even find this error…

Bententious
- 83
- 3
8
votes
2 answers
Angular 6: simple confirmation on page leaving
I need to make a simple confirm window and I saw a lot of examples of how to do it with extra actions (like waiting until file uploading of form is not field). But I need just make a default confirm window with a default text (like in a pic below)…

hofshteyn
- 1,272
- 4
- 16
- 33
8
votes
3 answers
RXJS Stop propagation of Observable chain if certain condition is met
Introduction
I'm trying to create a route guard in Angular2+ using Observable from the shared service which holds the string value of current user role.
The problem is obviously in shifting my mind from Promises to Observables.
What I made so far…

maljukan
- 2,148
- 2
- 25
- 35
8
votes
1 answer
How to redirect to child route from guard in angular
How do I redirect to a child route from a guard of the parent route while also protecting child routes from direct access*?
Problem with absolute navigation the guard on the parent component is called again in a loop when navigating to the child…

Markus
- 2,214
- 3
- 19
- 32
8
votes
6 answers
How to call canDeactivate in Angular when logout is clicked
In my current logout call, I have something like this:
getLogoutConfirmation(){
// get confirmation in modal and perform logout
// redirect to login page
}
Issue is, when logout is performed and redirect to login is called, the…

Gowtham Raj J
- 937
- 9
- 26