React Native-在嵌套导航中传递参数

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

在堆栈导航中为屏幕传递标题时,我总是收到错误消息。我不确定为什么我通过时我的参数为空

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",
          },
        });
      }}

此堆栈导航嵌套在另一个堆栈导航中。不确定如何传递参数。

react-native react-native-navigation
1个回答
0
投票
this.props.navigation.getParam('name')获取参数值
© www.soinside.com 2019 - 2024. All rights reserved.