在堆栈导航中为屏幕传递标题时,我总是收到错误消息。我不确定为什么我传递一个参数时我的参数是空的
TypeError: undefined is not an object (evaluating 'route.params.name')
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: 'My home' }}
/>
<Stack.Screen
name="Profile"
component={ProfileScreen}
options={({ route }) => ({ title: route.params.name })} <------here
/>
</Stack.Navigator>
</NavigationContainer>
这就是我触发它的方式
onPress={() => {
navigation.navigate("Profile", { name : "ABCD" });
}}
也尝试过
onPress={() => {
navigation.navigate("Root", {
screen: "Profile",
params: {
name : "ABCD",
},
});
}}
此堆栈导航嵌套在另一个堆栈导航中。不确定如何传递参数。
答案 0 :(得分:0)
您可以使用 this.props.navigation.getParam('name')
获得参数值