platform.registerBackButtonAction 的 Ionic 4 替代方案 [英] Ionic 4 alternative for platform.registerBackButtonAction

查看:11
本文介绍了platform.registerBackButtonAction 的 Ionic 4 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾了 Ionic 4 的新平台,似乎删除了 registerBackButtonAction 函数.

I looked around the new platform for the Ionic 4, it seems like the registerBackButtonAction function was removed from it.

是否有其他替代方法可以处理 Android 硬件后退按钮?

Are there any other alternatives to handle the Android hardware back button?

推荐答案

更新: 这已在 v4.0.0-beta.8 (dac9dc)

相关:如何将硬件后退按钮集成到ionic4导航中

这是在 GitHub 上跟踪的,位于 离子论坛推特
在官方修复之前,您可以使用此解决方法:

This is tracked on GitHub, in the Ionic Forums and Twitter
Until there is an official fix, you can use this workaround:

this.platform.backButton.subscribe(() => {
  // code that is executed when the user pressed the back button
})

// To prevent interference with ionic's own backbutton handling
// you can subscribe with a low priority instead
this.platform.backButton.subscribeWithPriority(0, () => {
  // code that is executed when the user pressed the back button
  // and ionic doesn't already know what to do (close modals etc...)
})

注意需要保存subscribe(...)的结果如果您想再次取消订阅.

Be aware that you need to save the result of subscribe(...) if you ever want to unsubscribe from it again.

旧答案:(截至 2018 年 4 月已过期)

Old answer: (out of date as of April 2018)

registerBackButtonAction只是一个包装器 对应科尔多瓦电话.

所以你可以直接调用registerBackButtonAction:

this.platform.registerBackButtonAction(() => { 
  // code that is executed when the user pressed the back button
});

并将其替换为:

this.platform.ready().then(() => {
  document.addEventListener("backbutton", () => { 
    // code that is executed when the user pressed the back button
  });
});

这篇关于platform.registerBackButtonAction 的 Ionic 4 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆