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.

Prevent back button routing if Dialog / SideNav is open

See original GitHub issue

We 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
alexdabastcommented, Aug 28, 2019

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.

if (this.dialog.openDialogs.length > 0) {
      this.dialog.closeAll();
      return false;
}
return true;

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”

1reaction
SvenBudakcommented, Jan 13, 2020

Someone maybe have an idea to disable the back button until this is fixed? The app feel very strange with the default back routing.

Read more comments on GitHub >

github_iconTop 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 >

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