Hardware back button with Ionic 4 Disable

Hi everyone,
How do I disable the hardware back button in android? I’ll explain. I would like the click to always remain on the same page it’s possible?
thanks

Have you tried this change in the app,module.ts?

IonicModule.forRoot({hardwareBackButton: false})
1 Like

Maybe something like

const sub = this.platform.backButton.subscribeWithPriority(9999, () => {
  // Do nothing
});
2 Likes

hi yes i’ve try but not work :frowning:

I’ve try your solution but not work, the event not fire

I am looking for how to do so only the back button material shipments on a specific page without taking into account the battery

finally I’ve found a solution, this work!!!

ionViewDidEnter() {
    document.addEventListener("backbutton",function(e) {
      console.log("disable back button")
    }, false);
}
6 Likes

For me this did work, but is there a way to restore the default functionality after using this?

I guess unsubsribe no?

if (sub) {
   sub.unsubscribe();
}
4 Likes

This is not working.

There is an openen issue on github:

1 Like

Thanks yrrrr it worked !,
It’s been a week I was looking for such a solution.

This work in Ionic 4.
in app.module.ts, in the imports:
imports: [BrowserModule, IonicModule.forRoot({hardwareBackButton: false})

Thank you so much!

1 Like

Wahh! Thank you, It works.

Thanks
Worked for me.

Thank you! It’s working for me.

It is 2020 now and i’m using Ionic 5 with Angular 9.
The solution that should work
IonicModule.forRoot({hardwareBackButton: false})
Still isn’t solved and still isn’t working

The soltion with the subscription on every component also isn’t working anymore

const sub = this.platform.backButton.subscribeWithPriority(9999, () => {
  // Do nothing
});

SO that leaves us the eventlistener

ionViewDidEnter() {
    document.addEventListener("backbutton",function(e) {
      // Do nothing
    }, false);
}

This one is working fine for Android at this moment and it follows the development guidelines from Angular

I’m searching for a solution where i can add the eventlistener only ones for the complete application

1 Like