Ionic v4-在硬件后退按钮上,我必须检查是否存在任何模态。如果存在任何模态,则关闭该模态。如果没有模态,则返回上一页
我在下面的代码行中使用了
代码:
private backButtonEvent() {
this.platform.backButton.subscribe(async () => {
debugger;
try {
let activeModal = await this.modalCtrl.getTop();
debugger;
if(activeModal) {
activeModal.dismiss();
return;
}
} catch(ex) { console.log(ex); }
this.routerOutlet.forEach((ro: IonRouterOutlet) => {
if (this.router.url === '/login' || this.router.url === '/home') {
if (this.router.url === '/home') {
this.common.confirmShow('Exit', 'Do you want to exit the app ?\r\nYou will be logged out after closing the app').then(d => {
if (d == 1) {
navigator['app'].exitApp();
}
}).catch(e => { console.log(e); });
} else if (this.router.url === '/login') {
navigator['app'].exitApp();
}
}
else if (ro && ro.canGoBack()) {
ro.pop();
}
});
});
}
这里,它始终满足activeModal true