我使用 ionic 4 创建了一个应用程序,我需要控制后退按钮。我使用了以下代码
this.backButtonSubscription =
this.platform.backButton.subscribeWithPriority(1, async () => {
if (this.router.url === '/registration') {
navigator['app'].exitApp();
}
});
这个订阅事件只对根页面起作用,对其他页面不起作用。
我想控制特定页面上的后退按钮以显示警报和其他内容,但现在当单击 Android 设备中的硬件后退按钮时,它会转到上一页。
最佳答案
下面的代码对我来说绝对没问题。
在 app.component.ts
中的 initializeApp()
方法中
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleLightContent();
this.splashScreen.hide();
this.platform.backButton.subscribeWithPriority(9999, () => {
if(this.router.url !== '/login') {
// Back button controls when user is not in Login Page
} else {
navigator['app'].exitApp();
}
});
});
}
关于要在 Ionic 4 中控制的 android 默认后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58377926/