I am creating an Android mobile app using Capacitor 6. My JavaScript app imports the Capacitor plugin “App” so that it can register an event listener for the hardware back button.
import { App } from "@capacitor/app"
App.addListener("backButton", this.onBackButton.bind(this))
The above code works, and my method “onBackButton” is called. The problem is that in addition to calling my callback method, it also navigates back to the previous page. This is contrary to the documentation here: App Capacitor Plugin API | Capacitor Documentation
The documentation at the above link states: " Listening for this event will disable the default back button behaviour, so you might want to call window.history.back()
manually."
However this is not what actually happens. The default back button behavior is NOT disabled and still is executed, despite the fact that I am listening for this event.
How can I suppress the default back button behavior?
1 post - 1 participant