我正试图将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' });
为什么我的参数在新屏幕中未定义?
不幸的是,我遇到过navigate(route, params, ...)
无法通过params
物体的情况,就像你一样。
作为一种解决方法,我使用另一种变体 - navigate({routeName, params, action, key})
,你可以找到here。它总是有效的。