Home > database >  the Hardware Back Button does not work with Ionic and Angular
the Hardware Back Button does not work with Ionic and Angular

Time:10-28

I haven't been able to get it to work for a few weeks now the Hardware Back Button. currently when we click back button the app is closed.

ionic info

this.platform.backButton.subscribeWithPriority(-1, () => {
  console.log("test")      
});

CodePudding user response:

I found a solution :

import { App } from '@capacitor/app';
    App.addListener('backButton', ({ canGoBack }) => {
     console.log(canGoBack);
      if(canGoBack){
       window.history.back();
       } else {
        App.exitApp();
       }
     });

watch out, on android : registerPlugin(com.capacitorjs.plugins.app.AppPlugin.class);

  • Related