Is there a way to override the Android back button behaviour?
-
I do not want it to go to the last visited route. I have gone to https://quasar.dev/vue-directives/go-back and there doesn’t seem to be any indication on how I can add an event handler to override the default back button behaviour.
-
well, I won’t help you with global android hook for system behaviour, BUT if you just want to protect your submitted forms or it is a similar problem, than you may be interested in router.replace functionality instead of router.push or router.go. This “replace” function allows you to directly manipulate browser history and protects your input forms:
https://router.vuejs.org/guide/essentials/navigation.html#history-manipulation
Of course, there may be situations, where for total form protection (for example transactional db store) you may need also this:
https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards
-
I’m already using $router.replace for everything. Currently, what happens is that when it is on another route, pressing the back button leads back to the home screen (which I do not want, I’d rather just send the app to the background).
Previously when I used OnsenUI before I discovered Quasar, I could write a function to manually override the Android back button event handler. I’m surprised quasar doesn’t seem to have this feature.
Or at least maybe a warning dialog could be displayed when the backbutton is pressed if the user has a partially filled form that hasn’t been saved.
-
quasar is using vue router you have to understand how to do that, and well you can add a listener for back button
document.addEventListener('backbutton', handler)
, and if you are using cordova there are several plugins for that as well. -
Got it on how I can add my own back button listener. How do I disable the default back button behaviour in quasar? I don’t have the listener function so I can’t call document.removeEventListener.