简体   繁体   English

React Navigation 5,未定义的参数

[英]React Navigation 5, undefined params

I have a RootNavigator (Stack) within there is a TabNavigator.我有一个 RootNavigator(堆栈),里面有一个 TabNavigator。 In the TabNavigator there are multiples Screens, including a Stack Navigator in which there is a screen called "Profile".在 TabNavigator 中有多个 Screens,包括一个 Stack Navigator,其中有一个名为“Profile”的屏幕。

What I am trying to do is just send a param from a screen of the RootNavigator, to Profile.我想要做的只是将一个参数从 RootNavigator 的屏幕发送到 Profile。

Root Navigator's Screen根导航器的屏幕

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

It navigates correctly to the screen, but when I get the route params they are undefined.它可以正确导航到屏幕,但是当我获得路由参数时,它们是未定义的。

Profile.js 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
      );
    }
  }, []);

I have also tried to send the params as follows but getting the same result.我也尝试按如下方式发送参数,但得到相同的结果。

Root Navigator's Screen根导航器的屏幕

// Navigate to the profile screen (nested navigator)   

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

Any ideas about what is going wrong here?关于这里出了什么问题的任何想法? Thanks.谢谢。

Okey I have found the solution.好的,我找到了解决方案。 It is like它像是

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

but, as in the lowest level I have a stack navigator called "Profile" in which there is other screen called the same, I have had to replace the "TabNavigator" with "Profile" and works fine.但是,在最低级别,我有一个名为“Profile”的堆栈导航器,其中还有其他相同的屏幕,我不得不用“Profile”替换“TabNavigator”并且工作正常。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM