The Hardware Back Button does not work with Ionic and Angular

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.

this.platform.backButton.subscribeWithPriority(-1, () => {
  console.log("test")      
});
CapacitorApp.addListener('backButton', ({canGoBack}) => {
  if(!canGoBack){
    console.log("exit");
    CapacitorApp.exitApp();
  } else {
    console.log("back")
    window.history.back();
  }
});

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);