Ionic 6 cannot disable back button

I am not able to disable the android back button, I have been trying to do this with Ionic/angular 6.1.9:

ionViewDidEnter() {
this.backButton = this.platform.backButton.subscribeWithPriority(9999, () => {
    alert('do nothing.');
});
}
ionViewWillLeave() {
    this.backButton.unsubscribe();
}

the alert is triggering but the page is still navigating to the previous page. I have also tried implementing the subscribeWithPriority in ionViewWillEnter and ionViewDidEnter, both do not stop the page from navigating to the previous page.
image

Is this for web or iOS/Android? I would love to disable it myself for web. I will test myself and let you know how it goes

Android hardware back button:
image

I know which one you are referring to. I have a Pixel phone and have it as a gesture but it would be nice to be able to control it in the browser but at this time there is no proper API (especially for modals) for it unless I haven’t looked hard enough.

1 Like

I figured my issue, the above code should stop the android back button, but in a previous page I had an eventListener listening to the back button and it was never removed, so I removed the listener onDestroy and now the page is not navigating back.

1 Like