我有一个离子3应用程序,我修改了硬件后退按钮的功能。它可以在页面上工作,但它不能确定是否存在覆盖视图(如modals和警报对话框)。
这里是我的代码
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();
}
}
});我希望有人能帮我这个忙。提前谢谢你
发布于 2019-12-11 07:50:12
我用MD解决了这个问题。利雅斯的回答:Solution
发布于 2019-12-06 16:55:09
声明一个变量:viewController:ViewController然后在您的页面或app.components.ts中,修改您的后退按钮句柄,使其类似于
this.platform.registerBackButtonAction(() => {
try{
this.viewController.dismiss()
}
catch(e){
console.log("error");
}
});https://stackoverflow.com/questions/59213163
复制相似问题