How To Prevent hardware back button to close ionic Modal

Hello.

I’m using Ionic 4 with Angular 8
I want to “Disable” modal dismiss when i press android hardware “back” button.

this.platform.backButton.subscribe(() => {
      console.log("Button Pressed");
    });

I can trace the event but i can’t prevent ionic to dismiss modal.

Set a variable to the var. For example let alert = …
alert.dismiss();

i have the same issue

You can alert user but can’t block. so the alert is useless.

The only solution i found is: Instead of modal, use the logic with page. So with nav controller you can set as root your page, then if user press back button, show alert and if confirm set back to root desired page.

UPDATE

I found a solution also with modals:

simply put backdrop:false and then subscribe to btn pressed and with alert cofirm add modal.dismiss()

2 Likes