Questions tagged [candeactivate]
39 questions
39
votes
5 answers
Angular's "CanActivate" interface is deprecated. How to replace it?
My Angular app includes a simple AuthGuard as shown below and there has never been a problem with it. Recently, I upgraded my Angular version from 15.1.4 to 15.2.0 and since then, my IDE indicates that both CanActivate and CanActivateChild are…

kellermat
- 2,859
- 2
- 4
- 21
4
votes
2 answers
Navigation issue with CanDeactivate guard in Ionic 5
In my Ionic 5 application I have the following navigation path.
PageHome -> PageA -> PageB
I have implemented CanDeactivate guard for PageA.
export class LeavePageGuard implements CanDeactivate{
canDeactivate(
component:…

Tapas Mukherjee
- 2,088
- 1
- 27
- 66
4
votes
1 answer
How to make Angular canDeactivate Service wait for Modal Dialog response?
I have a function inside the component to check if I can leave the route by evaluating a form status.
If the status matches to a contidition which I need to ask to leave the route, it shows up a dialog to confirm or cancel.
I call this function…

Diego de Lima
- 471
- 2
- 7
- 15
3
votes
0 answers
Use Guard canDeactivate to call function on refresh & reroute
I have a guard set in place in order to show a warning when the user switches and/or refreshes the page. I also implemented a way to call the function ngOnDestroy when these actions are made.
Problem: When the user refreshes trys to leave the…

André Clérigo
- 846
- 1
- 10
- 30
3
votes
1 answer
TypeError: Cannot read property 'canDeactivate' of null in IONIC 5
I am unable to implement canDeactivate guard in Ionic 5. Following are my code.
model.ts
export interface isDeactivatable {
canDeactivate: () => Observable | Promise | boolean;
}
leave-page.guard.ts
export class…

Tapas Mukherjee
- 2,088
- 1
- 27
- 66
3
votes
1 answer
How to subscribe asynchronously to matdialog service for candeactivate guard?
I have implemented candeactivate guard using angular forms validation.
If user clicks on an ngForm Field. and tries to navigate to different Tab, user will get a custom confirmation Popup, which will say "Discard Changes ? " and returns true or…

Chetan Birajdar
- 461
- 9
- 22
2
votes
0 answers
Prevent navigation in ngDestroy angular
I want to prevent the user from navigating away from the current page if the form is dirty. While this works with CanDeactivate guard, the problem is when I try to move on to another child component of the same parent, without a route change. The…

user5663970
- 119
- 2
- 13
2
votes
2 answers
Angular CanDeactivateGuard: How to wait for the right or the next value of an Obersavble?
I have a Service that emits events:
export class MyService {
private event = new BehaviorSubject('init');
event$ = this.event.asObservable();
constructor() { }
update(): void {
this.event.next('update');
}
accept(): void…

lampshade
- 2,470
- 3
- 36
- 74
2
votes
1 answer
canDeactivate() is not triggered on page navigation in Angular 8
I have a requirement of throwing a popup to the user when navigating to different component from the current component.
And based on the input from the user i will have to either have to allow him to navigate away or make him stay.
After a lot of…

WorksOnMyLocal
- 1,617
- 3
- 23
- 44
2
votes
0 answers
Ionic alert with Angular canDeactivate
I'm trying to use ionic-alert with Angular deactivate keeping the behaviors of the "confirm" function.
canDeactivate(component: UserFormComponent) {
if (component.userFormView.userForm.dirty) {
this.confirmDeactivate();
}
return…

Swarovski
- 581
- 2
- 8
- 25
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
0 answers
canDeactivate guard breaks routing history in angular
I am trying to implement canDeactivate guard for unsaved edit. And when I am testing, it seems that route history is getting broken. I know solution is there in angular but it is post v 12 and currently I am working on a project in angular 8. And I…

The Hungry Dictator
- 3,444
- 5
- 37
- 53
1
vote
2 answers
How to avoid navigating to another page while doing something in current page in Angular
Currently, I am on an HTML page and doing something. And if I mistakenly click another page then it will redirect to that page without getting any user confirmation.
This is my component.
export class MyComponent {
constructor(private router:…

Hans
- 308
- 7
- 20
1
vote
1 answer
Angular check component Instance from RouterStateSnapshot
I'm trying to implement a canDeactivate guard. For that purpose I need to know the component Instance of the route I want to navigate to.
canDeactivate(
component: ComponentCanDeactivate,
route: ActivatedRouteSnapshot,
state:…

dev_EEAN
- 21
- 1
- 4
1
vote
1 answer
angular 9, Can I route to somewhere else using canDeactivate?
Thank you for spending time here.
So Im having little problem with canDeactivate.
I made a page If I click go-back button, there will be a modal show up,
And user can choose either escape that page or not.
Which is works fine If I click only…

pearllv
- 238
- 1
- 2
- 10