我在我的app.component.ts中使用以下代码来处理硬件后退按钮:
this.platform.backButton.subscribeWithPriority(10, (processNextHandler) => {
console.log('Back press handler!');
if (this.location.isCurrentPathEqualTo('/home')) {
// Show Exit Alert!
console.log('Show Exit Alert!');
this.showExitConfirm();
processNextHandler();
} else {
// Navigate to back page
console.log('Navigate to back page');
this.router.navigateByUrl['/home'];
this.location.back();
}
});但它不起作用它只在午餐应用程序第一次工作,后来当我按下后退按钮应用程序关闭,我尝试了许多解决方案,但没有一个有效,无论是在模拟器和真实设备上使用不同版本的android (8,9,10)和相同的行为我的离子信息:
Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.6.13
@angular-devkit/build-angular : 0.803.29
@angular-devkit/schematics : 8.3.29
@angular/cli : 8.3.29
@ionic/angular-toolkit : 2.3.3
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 14 other plugins)
Utility:
cordova-res : 0.15.1
native-run : 1.4.0
System:
Android SDK Tools : 26.1.1 ()
NodeJS : v12.16.1 ()
npm : 6.13.4
OS : Windows 10发布于 2021-08-17 21:06:35
同样的代码也适用于我,问题出在ionViewWillLeave()函数中,当我删除它时,代码可以正常工作
发布于 2021-08-11 23:15:02
这是我的工作代码
this.plt.backButton.subscribeWithPriority(5, () => {
console.log("Back button Clicked")
var backRoute = this.prevRoute.getPreviousUrl();
if (this.auth.isAuthenticated.value && backRoute == '/login') {
navigator['app'].exitApp();
} else {
this.router.navigateByUrl(backRoute)
}
})https://stackoverflow.com/questions/68749068
复制相似问题