[英]react-native-router-flux : No React lifecycle method is getting called on back navigation
我正在开发一个反应原生应用程序。 我在应用程序中使用react-native-router-flux库进行导航。
该库工作正常但在返回导航时没有反应生命周期方法被调用。
假设我在第2页上按下了按钮,它会导航到第1页,第2页的componentWillUnmount()被调用但第1页的生命周期方法没有被调用 。
我想根据新的状态刷新页面1。
任何帮助将不胜感激。
导航回来时,默认Actions.pop()
时不带参数。 为了刷新第1页,您需要覆盖后退按钮的功能并调用Actions.pop({refresh:{<propsToSetToPage1>}})
。 这应该触发第1页中的componentWillReceiveProps(nextProps)
,其中nextProps是你放在pop()中的新道具。
以下是来自react-native-router-flux的文档:
Actions.pop() will pop the current screen. It accepts following optional params:
{popNum: [number]} allows to pop multiple screens at once
{refresh: {...propsToSetOnPreviousScene}} allows to refresh the props of the scene that it pops back to
PS。 如果您正在为Android开发,您可能希望在用户按下硬件后退按钮时执行此操作。 在React Native的官方文档上查看BackAndroid 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.