ionic-framework - 构建时platform.registerBackButtonAction()不起作用--prod
问题描述
我正在使用 ionic 3 进行项目。
ionic cordova run android
我使用这个命令来运行应用程序。
在这个操作platform.registerBackButtonAction()
中工作正常..
但是,如果我使用该ionic cordova run android --prod
选项,platform.registerBackButtonAction ()
则无法正常工作。
任何帮助表示赞赏。
下面是我处理硬件后退按钮的代码。
this.platform.registerBackButtonAction(() => {
let view = this.nav.getActive();
if(view.component.name == "NonetworkPage"){
if (!this.showedAlert) {
this.confirmExitApp();
} else {
this.showedAlert = false;
this.confirmAlert.dismiss();
}
}else{
if (view.component.name == "HomePage") {
if (!this.showedAlert) {
this.confirmExitApp();
} else {
this.showedAlert = false;
this.confirmAlert.dismiss();
}
} else if (view.component.name != "HomePage" && view.component.name != "LoginPage") {
if (this.nav.length() == 1) {
this.nav.setRoot(HomePage);
} else if (this.nav.length() > 1) {
this.nav.pop();
}
} else if (view.component.name == "LoginPage") {
this.confirmExitApp();
}
}
});
以下是确认退出弹出窗口
confirmExitApp() {
this.showedAlert = true;
this.confirmAlert = this.alertCtrl.create({
title: "Exit App?",
message: "Are you sure you want to exit App?",
enableBackdropDismiss: true,
cssClass: 'confirmCustomCss',
buttons: [
{
text: 'No',
handler: () => {
this.showedAlert = false;
return;
}
},
{
text: 'Yes',
handler: () => {
this.platform.exitApp();
}
}
]
});
this.confirmAlert.present();
}
解决方案
因为 prod 标志会缩小我们的代码并混淆页面名称,但是您可以通过使用此代码来解决此问题,可能希望它对您有所帮助,并且它将在 build --prod 和 build 上运行
platform.registerBackButtonAction(() => {
let view = this.navCtrl.getActive();
let page = view ? this.navCtrl.getActive().instance : null;
if (page && (page instanceof Mypage)
不要忘记将 Mypage 导入 app.component.ts
推荐阅读
- python - Tensorflow:垂直堆叠矩阵的最佳方法?
- python - Python OpenCV Stitcher 类文档
- python - 导出的 xml 格式不正确但出现在一行中?
- angular - Angular 6 build,刷新页面时未找到错误 404
- html - Angular 6 孩子/家长沟通
- google-apps-script - 缺少云平台项目
- python - 姜戈2。Python 在单独的文件中可用
- android - 添加 facebook 依赖 gradle 错误
- rxjs - 在 Redux-Observable 中,ofType 必须紧跟其中一个映射运算符吗?
- python - 张量流量化:没有这样的包