请在 ionic3
中找到以下Android硬件后退按钮操作的代码 . 由于 Ionic4
使用角度路由导航如何为后退按钮发生弹出事件?如果我们想要弹出到最后一页,我们可以使用以下代码 this.navCtrl.goBack('/products');
. 但是如何在 ionic4
中将它用于Android硬件后退按钮操作呢?
Ionic3硬件后退按钮动作
this.platform.registerBackButtonAction(() => {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (activePortal) {
activePortal.dismiss();
} else {
if (this.nav.canGoBack()) {
***this.nav.pop();***
} else {
if (this.nav.getActive().name === 'LoginPage') {
this.platform.exitApp();
} else {
this.generic.showAlert("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
}
}
}
});
2 回答
Update: 这在dfac9dc修复
Related: ionic4 replacement for registerBackButtonAction
这是在GitHub,Iconic Forum和Twitter上跟踪的
在有正式修复之前,您可以使用下面的解决方法 .
使用
platform.backButton.subscribe
(参见here),代码ionic使用its own back button is pressed和新router-controller一起得到这样的东西:Try This: app.comonent.ts
it's work for me, in ionic v4.1.2