【问题标题】:React Navigation 5, undefined paramsReact Navigation 5,未定义的参数
【发布时间】:2020-07-03 01:29:33
【问题描述】:

我有一个 RootNavigator(堆栈),里面有一个 TabNavigator。在 TabNavigator 中有多个 Screens,包括一个 Stack Navigator,其中有一个名为“Profile”的屏幕。

我想要做的只是将一个参数从 RootNavigator 的屏幕发送到 Profile。

根导航器的屏幕

// Navigate to the profile screen
navigation.navigate("Profile", {
  isUploadingContent: true,
});

它可以正确导航到屏幕,但是当我获得路由参数时,它们是未定义的。

Profile.js

  useEffect(() => {
    // Check if content is uploading...
    if (props.route.params.isUploadingContent) {
      toastRef.current.show(
        "Your photo will be available in a few seconds",
        3500
      );
    }
  }, []);

我也尝试如下发送参数,但得到相同的结果。

根导航器的屏幕

// Navigate to the profile screen (nested navigator)   

navigation.navigate("TabNavigator", {
  screen: "Profile",
  params: {
    isUploadingContent: true,
  },
});

关于这里出了什么问题的任何想法?谢谢。

【问题讨论】:

    标签: javascript reactjs react-native expo react-navigation


    【解决方案1】:

    好的,我找到了解决方案。就像

    navigation.navigate("TabNavigator", {
      screen: "Profile",
      params: {
        isUploadingContent: true,
      },
    });
    

    但是,在最低级别,我有一个名为“Profile”的堆栈导航器,其中还有其他屏幕称为相同,我不得不将“TabNavigator”替换为“Profile”并且工作正常。

    navigation.navigate("Profile", {
      screen: "Profile",
      params: {
        isUploadingContent: true,
      },
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 2020-05-29
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多