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

问题描述 投票:0回答:1

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

<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)}
react-native react-navigation
1个回答
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});
© www.soinside.com 2019 - 2024. All rights reserved.