question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: make CanDeactivate guard work with stacked navigation

See original GitHub issue

Feature Request

Assume that you have form with few controls. Inside that form there’s a button that navigates to SearchPage which allows you to look for item to be selected. After clicking an element inside SearchPage you go back (pop) to the form.

Additionally there’s a CanDeactivate guard configured to prevent user from loosing unsaved data.

The problem is that I wan’t to display leave confirmation only when FormPage is about to be destroyed. Confirmation should not be shown while navigating to SearchPage since FormPage is not destroyed and it’s still present in the DOM.

Related Code

Currently canDeactivate is always called. Demo: https://stackblitz.com/edit/ionic-angular-v5-r8uzq2

In case I missed something and it’s possible to do it, let me know.

Edit Workaround

I found temporary workaround. Inside my CanDeactivateGuard I’m accessing private(!) field of NavController - direction. If direction=='forward' then I’m skipping confirmation dialog.

Maybe it’ll be enough, if ionic would append direction to ActivatedRouteSnapshot.data. Then I could easily use it inside canDeactivate method.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
indraraj26commented, May 6, 2020

Maybe it’ll be enough, if ionic would append direction to ActivatedRouteSnapshot.data. Then I could easily use it inside canDeactivate method.

This will only handle back , what if there are 3 action on page, I want to allow him to go on 1 action but not on other action. and all action are forward navigation.

I think router.events would be better option here.

Lets wait for Liam response on this.

0reactions
ionitron-bot[bot]commented, Jun 12, 2020

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

feat: make CanDeactivate guard work with stacked navigation ...
Assume that you have form with few controls. Inside that form there's a button that navigates to SearchPage which allows you to look...
Read more >
Navigating to the same route cancelled by the canDeactivate ...
If i try to navigate to a route that is cancelled by the canDeactivate guard, its not happening . Is their any workaround...
Read more >
Controlling Navigation with CanDeactivate Guard
The CanDeactivate Guard to prevent the user from accidentally navigating away.
Read more >
60. Controlling Navigation with CanDeactivate Route Guard in ...
Hi FriendsIn this video, we will see how to implement the CanDeactivate route guard in the angular.If you like my video, please subscribe...
Read more >
Disable Navigation With Browser Back Button in Angular
In this short article, we presented how the CanDeactivate Guard in Angular can be used to disable navigation with the browser's back button,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found