javascript - React Navigation 5,未定义的参数
问题描述
我有一个 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,
},
});
关于这里出了什么问题的任何想法?谢谢。
解决方案
好的,我找到了解决方案。它像是
navigation.navigate("TabNavigator", {
screen: "Profile",
params: {
isUploadingContent: true,
},
});
但是,在最低级别,我有一个名为“Profile”的堆栈导航器,其中还有其他相同的屏幕,我不得不用“Profile”替换“TabNavigator”并且工作正常。
navigation.navigate("Profile", {
screen: "Profile",
params: {
isUploadingContent: true,
},
});
推荐阅读
- perl - Perl -M 找不到模块的硬编码路径
- sql - 是否有任何优化的方法来编写 SQL 查询来查找两个数据集之间的差异?
- c# - 是否可以像加载 XML 文件一样使用 XDocument 的功能加载 DGML 文件?
- ios - 有没有捷径可以知道,当我运行我的应用程序时,我在哪个视图控制器中?
- java - Leadtools.RasterException:本机库 Ltkrnx.dll 已加载到另一个类加载器中
- c# - 为什么你不能运行一个任务并用另一种方法捕获它
- sql - 在sql中转换时间
- c++ - 如何分别在R和C++中做两个矩阵的矩阵乘积
- sql - rexp_like - 似乎无法理解它是如何工作的
- javascript - 与服务器的连接不断失败连接 ETIMEDOUT 94.195.191.104:27017