Prevent back button routing if Dialog / SideNav is open
See original GitHub issueWe have already closeOnNavigation
for Dialogs. That was a good start… But for make feeling a PWA like a native app we need more options to change also the routing a bit. 95% of users use the back button in my apps instead of the X button to close dialogs and sidenavs. the problem is that in background happens also a route change.
If Dialog or SideNav is open it should just close them without any route change.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Close Angular Material Dialog On Browser Back
As a workaround you can add CanActivateChild guard to the root route. The guard will cancel navigation if an dialog is open and...
Read more >Dialog / How To / Close Dialog when click outside of its region
Close Dialog when click outside of its region in Angular Dialog component ... By default, dialog can be closed by pressing Esc key...
Read more >close modal on back button click - Material Design for Bootstrap
Modal and sidebar closes when back button is clicked on mobile Android ... is to close the modal instead of changing the route,...
Read more >Window: popstate event - Web APIs | MDN
The popstate event of the Window interface is fired when the active history entry changes while the user navigates the session history.
Read more >Building a dialog component - web.dev
A foundational overview of how to build color-adaptive, responsive, and accessible mini and mega modals with the element.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Custom guard introduces a new issue.
Here is how to reproduce the issue on this stackblitz https://angular-material-modal-guard.stackblitz.io/
What I did: Create a custom CanDeactivate guard on all my routes. The custom guard checks if any dialog is open an close them all and cancel the navigation.
The issue: Everything seems to work as expected but, if you hit a second time the back button of your browser once the modal has been closed by the guard, you do not navigate to your previous route but the second previous route.
Scenario: You are on route “first” You navigate to route “second” You navigate to route “third” You open the dialog You close the dialog with the back button Your hit the back button again
What you should expect is to land on route “second” What happen you land on route “first”
Someone maybe have an idea to disable the back button until this is fixed? The app feel very strange with the default back routing.