How can I prevent default navigation when pressing hardware back button? I've tried registerBackButtonAction
, but then it overwrites behavior of back button in every page which I don't want.
This didn't help either.
document.addEventListener("backbutton", (event) => {
event.preventDefault();
}, false);
As you can see in Ionic docs
registerBackButtonAction
returns a function:So you can use that function to restore the default behavior when leaving the page, like this:
So as you can see, the key is to store the callback of the
registerBackButtonAction
method and use it later when leaving the page (or when you want to restore the default behavior):