首页 > 解决方案 > 检测在导航器之间移动的导航动作

问题描述

这就是我的导航器的定义方式:

const navigatorA = TabNavigator({
    screenA :{screen: navigatorX},
    screenB: {screen: navigatorY},
});

const navigatorX = Stacknavigator({
     home: {screen: home},
      options: {screen: options},
});

const navigatorY = StackNavigator({
     profile: {screen: profile},
     settings :{ screen: settings}
})

我通过参数喜欢this.props.navigation.navigate({routeName:'profile', params:{user:{thisUser}});

当用户从配置文件屏幕导航回主屏幕时,我想重置导航参数,而不是当用户从配置文件屏幕导航到设置屏幕时。

使用this.props.navigation.setParams({user:nulll});incomponenWillUnmount无法完成任务,因为即使用户从配置文件导航到设置,它也会重置参数。

我也尝试过使用willBlur事件侦听器,但它不适用于堆栈导航器,只能在选项卡导航器中使用。

标签: react-nativereact-navigation

解决方案


推荐阅读