To find more information :
Questions tagged [angular-router-guards]
289 questions
1
vote
0 answers
Angular CanDeactivateGuard generic for every component
I have like 15-20 components all of them with forms, and I want to prevent navigation on form dirty. I've seen I can make it trough CanDeactivateGuard, but I do not want to copy/paste same code on every component. I want it more maintainable. How…

Esteban Chornet
- 928
- 3
- 14
- 38
1
vote
1 answer
How to prevent routing and instead display a modal when navigation on a non-permission page?
In my app you can find many routerLinks everywhere across the application. Some of them may not be accessible for some users according to their roles. My auth-guard-service handles this cases.
But what in those cases happens is that the user gets…

L. Heider
- 1,579
- 1
- 14
- 31
1
vote
1 answer
Redirect Empty path to a component
As, I was not able to redirect an empty path to a component. I have gone through many questions here but none of the solutions solves it.
When a user hits a URL first time. I wants him to redirect to a component.
The Approach i used:
{ path: '',…

Ankit Manchanda
- 562
- 6
- 21
1
vote
2 answers
Unable to router.navigate to lazy loaded child modules
I'm new to angular. I am starting with the latest version, 8.
I am trying to write an app. The initial state of the route is path:'' and I would like to determine the next route based on some condition in the base path here. If the condition is…

Super Test
- 25
- 7
1
vote
1 answer
How to use CanDeactivate guard when leave application (NOT component)
In my application, the user can be tested, see the test results. And this is all without registration (such as login-password). But if he wants to leave the application, I want to offer him to register, otherwise his data will not be saved.
I do not…

Kontar Maryna
- 11
- 3
1
vote
2 answers
CanActivateChild not running
I have a problem that when I logout and navigate to /, canActivateChild guards are not executed to redirect to login.
My requirement is that none of the app is accessible without login.
Here is my root Route config:
const appRoutes: Routes = [
{
…

f.khantsis
- 3,256
- 5
- 50
- 67
1
vote
1 answer
Angular 7 Routes Protecting is not working
I have been trying to work on route protecting in Angular 7 but it has not been working. The code that I have tried is given below. Can anyone help me with what might be going wrong? There are no errors, but i am not getting the desired output…

Colleen
- 63
- 7
1
vote
1 answer
how to prevent user from routing , when token is expired
I am working on Angular 7 Application
I am using JSON Web Tokens (JWT) to secure my Angular Application
I want to check weather token is expired , and if it is expired I want to prevent user from routing . except home page and next to home page…

Testing Anurag
- 603
- 4
- 13
- 26
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
1
vote
0 answers
Is there a way to get the Angular Router guard, CanDeactivate, working as a guard/interface in a form component?
I read about using CanDeactivate to detect whether a user leaves a form/route and this is what I need in my project. I tried to implement this SO answer: SO Answer
When I view my user-form component, I enter information into one of the inputs and…

Taylor Ferguson
- 13
- 4
1
vote
2 answers
Angular guard with multiple conditions and redirects
I want to create a complex router guard that checks if the user is authenticated in the web application but, if so, it checks also other condition and for each true condition it redirects to a page (that is however under the same router guard). For…

bertonc96
- 772
- 2
- 13
- 24
1
vote
1 answer
How to send return value to CanDeactivate Guard after close the mat-dialog | Angular CanDeactivate Guard | Angular Material Dialog
I'm using CanDeactivate Guard for find out the unsaved changes and If changes occurred I am showing the confirm material dialog, before leaving the page. Based on the dialog action I will return the Boolean value.
CanDeactivateGuard.ts:
export class…

Dinesh Kannan
- 135
- 1
- 1
- 7
1
vote
1 answer
Angular 5 Show browser alert when query param changes
I have a Parent component Item which has route '/Item'.
I have two children component name Catalogue component and AddSize component.
By default, Catalogue component will be loaded with route '/item?q=catalogue'. Then user select product then route…

madhan kumar
- 1,560
- 2
- 26
- 36
1
vote
3 answers
Accessing component properties from CanDeactivate guard
I have multiple forms in an app and I have a CanDeactivate guard that prompts the user to confirm whether they want to leave the page without first saving the forms they have edited. Each component with forms has a hasBeenEdited function that…

charlitos
- 105
- 2
- 10
1
vote
1 answer
Configure Route Guard
I have a route guard that needs to be configured. On some route we want to check if our user client is ready, on some others we want to check if our team client is ready etc.
I've my route guard that looks like this
@Injectable({
providedIn:…

Ced
- 15,847
- 14
- 87
- 146