参数更改后,React导航不会刷新页面

时间:2019-04-12 11:52:37

标签: react-native react-navigation

我正在使用反应导航在页面之间导航。 我有2页。我们将它们称为A和B。我在A页上有一些卡,并且在卡上有可触摸的不透明性,可以导航到具有不同ID(使用此ID从服务器获取数据)的B页。

<TouchableOpacity style={styles.button} onPress={() => this.props.navigation.navigate('pageB',{id:this.props.id})} >
   <Text>PageB</Text>
</TouchableOpacity>

在第一次导航时效果很好。但是,当我导航回页面A(使用侧面菜单)并选择另一个导航按钮导航页面B(不同的参数)时,它会通过第一次导航将我导航到同一页面。

我曾经尝试过使用导航键,但是我想我可以做到;

this.props.navigation.navigate('pageB',{id:this.props.id}, this.props.id)}

1 个答案:

答案 0 :(得分:0)

您必须像这样设置新参数:

    static navigationOptions = ({ navigation }) => {
    let value = navigation.getParam("value");
    return {
        title: name,
        headerRight: () => (<Button title="Edit" onPress={() => navigation.navigate("Edit", { val: value})} />),
    };

并始终将新参数设置在这样的地方:

let value = this.state.value;
this.props.navigation.setParams({value});
相关问题