this.nav.canGoBack() not works in modal!

On click hardware back button, this.nav.canGoBack() not works when modal is open otherwise it works.

What to do?
Actually, It shows alert to exit app when my apps settings modal page opened. On navigated pages it works well and only show app exit alert in home. What to do in case of modal??

 this.platform.registerBackButtonAction(() => {
               if (this.nav.canGoBack()) {
                    this.nav.pop();
               } else {
                   if (this.alert) {
                       this.alert.dismiss();
                       this.alert = null;
                   } else {
                       this.exitApp();

                   }
                }
            });


//showing modal like this : 
let settingsModal = this.modalCtrl.create(Settings);
        settingsModal.onDidDismiss(data => {
            this.settingsData.FontSize = data.FontSize;
        });
        settingsModal.present();

//Dissmissing modal like this : 
 this.viewCtrl.dismiss(data);
1 Like