cookya
cookya

Reputation: 3297

How to close modal on hardware back button in ionic app?

I'm using Ionic 5 in my pwa application (angular framework), and I want to close the opening modal/popover (if exist) when the user uses the hardware back button..

I couldn't find any solution online that works on ionic 4+ pwa applications.

Any help will be appreciated.

Upvotes: 2

Views: 1327

Answers (1)

nktshn
nktshn

Reputation: 1175

You can add a handler for the backbutton.

Cordova: Inject Platform in a constructor and

this.platform.backButton.subscribe(() => {
  // close modal here
});

Capacitor:

import { Plugins, AppState } from '@capacitor/core';
const { App } = Plugins;
App.addListener('backButton', () => {
  // close modal here
});

Upvotes: 2

Related Questions