【发布时间】:2019-01-13 00:21:31
【问题描述】:
请在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");
}
}
}
});
【问题讨论】:
-
我们的解决方法有效,您可以试试吗?