backButton subscribe not working

help me on this

import { Platform } from '@ionic/angular';
  constructor(
    public platform: Platform,
  ){
    this.platform.backButton.subscribe((dd) => {
      alert(dd);
    });
  }

Use this inside your home page constructor do like below
this.platform.backButton.subscribe(() => {
this.closeCounter++;
console.log(this.router.url);
if (this.router.url == “/home”) {
if (this.closeCounter == 2) {
navigator[‘app’].exitApp();
} else {
this.presentToast();
}
}
else {
//go back
this.router.navigateByUrl("/home");
}
});

cheers!!