I’m not sure what I’m missing here. Given that each page in Ionic is a component, then adding the above constructor code in your page’s constructor should work.
platform.ready().then(() => {
//back button handle
//Registration of push in Android and Windows Phone
var lastTimeBackPress = 0;
var timePeriodToExit = 2000;
platform.registerBackButtonAction(() => {
let ref = this.viewCtrl.pageRef();
console.log('Check your needed page ref name', ref.nativeElement.localName)
if(ref.nativeElement.localName =='page-no-internet'){
//Double check to exit app
if (new Date().getTime() - lastTimeBackPress < timePeriodToExit) {
this.platform.exitApp(); //Exit from app
} else {
let toast = this.toastCtrl.create({
message: 'Press back again to exit App?',
duration: 3000,
position: 'bottom'
});
toast.present();
lastTimeBackPress = new Date().getTime();
}
}else{
this.nav.pop();
}
});
}