I’ve been trying to make the app to exit when there is no modals, sheets, etc. open. My app doesn’t have any routes so I don’t need “Back” button to go back in history.
I tried to fiddle with the “backbutton” event handler on cordova-app.js by rewriting all if conditions to else-if blocks, but had no luck. Any ideas or suggestions?
There are answers for version below 6.0. Before upgrading to 6.0 I had my own handler which worked perfectly. With 6.0 I wanted to use built-in method, but it doesn’t work quite I need.
in my src/js/cordova-app.js (in method handleAndroidBackButton):
document.addEventListener(‘backbutton’, function (e) {
…
f7.dialog.confirm(‘a u sure?’, function () { navigator.app.exitApp();
});
}, false);
This is insufficient, you need to be able to close popups and popups with back button also. I need to figure out how to exit only if there is no popups, popover and other modals open before exiting the app.
It turns out, the back button handler in cordova-app.js for some reason is executed twice. To fix this, simply remove the handler and put the code in the app.vue (or similar for your framework) mounted() method.