【发布时间】:2019-03-20 19:49:03
【问题描述】:
问题是,当在手机/桌面浏览器中单击后退按钮时,PWA 将关闭,因为默认情况下 ionic3 PWA 没有处理后退按钮。我到处搜索可以处理 ionic3 PWA 的后退按钮的解决方案,但我找不到当前有效的解决方案。
我在这里找到了解决方案: Android Back Button on a Progressive Web Application closes de App
但我不知道如何在我的应用程序中修复它,因为我试图在我的应用程序初始化时将它扔到我的代码中,现在它完全禁用了后退按钮,所以现在我正在寻求帮助。
我在 app.components.ts 中的代码
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
//Back button handling
window.addEventListener('load', function() {
window.history.pushState({}, '')
})
window.addEventListener('load', function() {
window.history.pushState({}, '')
})
window.addEventListener('popstate', function() {
window.history.pushState({}, '')
})
window.addEventListener('load', function() {
window.history.pushState({ noBackExitsApp: true }, '')
})
window.addEventListener('popstate', function(event) {
if (event.state && event.state.noBackExitsApp) {
window.history.pushState({ noBackExitsApp: true }, '')
}
})
});
}
【问题讨论】:
标签: android ionic3 progressive-web-apps