我有一个ionic 3应用程序,并且修改了硬件后退按钮的功能。它可以在页面上运行,但无法确定是否存在模式视图和警报对话框之类的叠加视图。
这是我的代码
this.platform.registerBackButtonAction(() => {
let nav = app._appRoot._getActivePortal() || app.getActiveNav();
let activeView = nav.getActive().instance;
if (activeView != null) {
if (nav.canGoBack()) {
if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
// do something
} else {
nav.pop();
}
} else if (activeView.isOverlay) {
activeView.dismiss();
} else {
let alert = this.alertCtrl.create({
title: 'Ionic App',
message: 'Do you want to close the app?',
buttons: [{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Application exit prevented!');
}
},
{
text: 'Close',
handler: () => {
this.platform.exitApp();
}
}]
});
alert.present();
}
}
});
我希望有人可以帮助我。预先谢谢?
答案 0 :(得分:0)
声明一个变量:viewController:ViewController
然后在您的页面或app.components.ts中,将后退按钮的句柄修改为类似于
this.platform.registerBackButtonAction(() => {
try{
this.viewController.dismiss()
}
catch(e){
console.log("error");
}
});
答案 1 :(得分:0)
我用MD解决了它。里亚斯的答案在这里:Solution