ionic 4 prevent/disable device hardware backbutton
initializeApp() {
this.platform.ready().then(() => {
this.platform.backButton.subscribeWithPriority(9999, () => {
document.addEventListener('backbutton', function (event) {
event.preventDefault();
event.stopPropagation();
console.log('hello');
}, false);
});
this.statusBar.styleDefault();
});
}
I found out how to undo it (give back button previous functionality):
Your observer is pushed to the this.platform.backButton.observers
array. So you just have to pop the last element of the list:
this.platform.backButton.observers.pop();
Hope it helps somebody.
05-02-2020
This works for me.
app.component.ts
async initializeApp(): Promise<void> {
await this.platform.ready();
this.platform.backButton.subscribeWithPriority(1, () => { // to disable hardware back button on whole app
});
}