Router: ability to intercept back button or tab close that would terminate the app
See original GitHub issue[ ] bug report
[x] feature request
[ ] support request
Current behavior Cannot intercept when the back button or closing the current browser tab will close the app w/o a warning.
Expected behavior Should be able to detect both actions and take appropriate actions. Could be done with router hook or some other means.
I understand that browsers differ in how they handle this but the router should have a way to cope. Barring that, we need documentation to cope.
Minimal reproduction of the problem with instructions
- Launch routing app running on localhost (e.g., http://localhost:3000)
- Paste another site into address bar (e.g., google.com)
- Paste the locally running app into address bar (e.g., http://localhost:3000)
- Hit the back button
You’ll be taken to google.com
w/o interruption.
What is the motivation / use case for changing the behavior?
Don’t lose work or context by accidental over-clicking of back button or closing the tab.
Please tell us about your environment:
- Angular version: 2.2.0
- Browser: all
- Language: all
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Android Back Button on a Progressive Web Application closes ...
First up, when there's no browser history for the page that the user is on, pressing the back button immediately closes the app....
Read more >Using Router Events To Detect Back And Forward Browser ...
Hi, as soon as I am pressing back button on landing page, it navigates away to default browser page. The app exits without...
Read more >Preventing going back - React Navigation
The user closes the app (e.g. by pressing the back button on the home screen, closing the tab in the browser, closing it...
Read more >NET MAUI Shell navigation - Microsoft Learn
NET MAUI Shell apps can utilize a URI-based navigation experience that permits ... Navigation events; Navigation deferral; Pass data; Back button behavior.
Read more >Provide custom back navigation - Android Developers
For example, when using a WebView , you might want to override the default Back button behavior to allow the user to navigate...
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 Free
Top 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
The behavior for window.onbeforeunload changed between 2 and 4:
I can’t demonstrate this in a plunkr because plunkr binds its own handler to window.onbeforeunload.
The canDeactivate hook is not run when the page is reloaded, so I can’t see a way to block page reloads, for example if there are unsaved changes, in Angular 4. This is something that should be supported as per the original issue. @wardbell
Should
window.onbeforeunload
be used for this?