AliAzad
AliAzad

Reputation: 263

Device back button event in ionic4 not working

I want to use the device back button event in ionic4 to do something but it not work.

my app.component.ts

export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
    this.backButtonEvent()
  }
  backButtonEvent() {
    this.platform.backButton.subscribeWithPriority(2, () => {
      console.log("clicked to the back button")
    });
  }
}

Upvotes: 1

Views: 38

Answers (1)

Paresh Gami
Paresh Gami

Reputation: 4792

You can catch hardware back button event like this

this.sub = this.platform.backButton.subscribeWithPriority(9999, () => {
 // Do your stuff here
});

Upvotes: 1

Related Questions