feat: make CanDeactivate guard work with stacked navigation
See original GitHub issueFeature 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:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
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.
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.