反应导航未定义的参数

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

我正试图将params传递到一个新的屏幕,并像提到的here一样实现它。

我有以下TouchableOpacity按钮。

<TouchableOpacity
onPress={() => {
  this.props.navigation.navigate('SomeScreen', {
  title: 'Title',
  subTitle: 'Subtitle',
});
}}
>

在另一页(让我们称之为Somescreen),我有以下内容:

render() {
const { navigation } = this.props;
const title = navigation.getParam('title');
}

但上面的title未定义:

{params: undefined, routeName: "Somescreen", key: "id-xx"}

我的rootStack:

const RootStack = createStackNavigator({
  SomescreenA: { screen: SomescreenA },
  SomescreenB: { screen: SomescreenB },

}, { headerMode: 'none' });

为什么我的参数在新屏幕中未定义?

react-native react-navigation
1个回答
0
投票

不幸的是,我遇到过navigate(route, params, ...)无法通过params物体的情况,就像你一样。

作为一种解决方法,我使用另一种变体 - navigate({routeName, params, action, key}),你可以找到here。它总是有效的。

© www.soinside.com 2019 - 2024. All rights reserved.