How to close Ionic modals using the hardware back button

Uses this code:
@HostListener(‘document:ionBackButton’, [’$event’])
private async overrideHardwareBackAction($event: any) {
await this.modalController.dismiss();
( Link : )

Having a problem! See the link ->

The problem with the code:

  • It closes/dismiss modal is fine!
  • But it also pushed back the page from where the modal is opened. Means it pop the page behind the modal.

This should not happen the page should not pop — only modal should close.