How to close modal/Alert on back button in ionic4 (PWA)

I am new to Ionic 4, I have managed to implement a PWA using ionic 4 with Angular.
I am having a hard time figuring out how to close modals/Alerts/ActionSheets on back-button on browser (Desktop & mobile) when served as a PWA. When I press back when a modal is open, the modal stays open and background page is navigated back.
I have tried workarounds from different forums and posts like

  1. this.platform.backButton.subscribeWithPriority(0, async () => {…

  2. fromEvent(document, ‘backButton’).subscribe(() => {…

but none of then are working for me, please can anyone help me with this, need to go production ASAP.

Currently using : ionic : 4.6.2 Angular: 7.2.2

A modal can be dismissed by calling the dismiss method on the modal controller and optionally passing any data from the modal.

Thank you for the response.
but I wanted to know, how we can trigger dismiss method on hardware back button on device and on desktop browser back navigation button is pressed.