platform.registerBackButtonAction() 在构建时不起作用 --prod
platform.registerBackButtonAction() not working when build --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)
不要忘记将我的页面导入 app.component.ts
在 ionic 3 中,这给出了当前页面的名称:
const currentActivePage = this.nav.getActive().id;
而且可以用
来比较
if(currentActivePage == 'LoginPage')
this.platform.registerBackButtonAction(() => {
let view = this.nav.getActive();
let currentRootPage = view.component;
if(currentRootPage == MyPage)
});
对我有用。
我正在使用 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)
不要忘记将我的页面导入 app.component.ts
在 ionic 3 中,这给出了当前页面的名称:
const currentActivePage = this.nav.getActive().id;
而且可以用
来比较if(currentActivePage == 'LoginPage')
this.platform.registerBackButtonAction(() => {
let view = this.nav.getActive();
let currentRootPage = view.component;
if(currentRootPage == MyPage)
});
对我有用。