react-native - 将参数传递给嵌套导航器
问题描述
我正在尝试将参数传递给另一个基于类的组件。当我在第一页(登录页面)上提醒值时,我得到了正确的结果,但在另一页(主页)上我得到了一个错误!但是,我要导航到的主页有 4 个选项卡,我正在尝试将参数传递给每个选项卡,从 profile 开始。
登录.js:
login = () => {
if (this.state.inputFieldsStatus == true)
{
fetch('http://192.168.0.6:3000/login', {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
alert(JSON.stringify(res.message));
if (res.success === true ) {
this.props.navigation.navigate('Home',
{
screen: 'Messages',
params:
{
message: res.message,
otherParam: 'anything you want here'
}
},
{
screen: 'Profile',
params:
{
message: res.message,
otherParam: 'anything you want here'
}
}
);
} else {
this.setState({passwordError: res.message })
}
})
.done();
}
else
{
// alert(' Please fill in all fields! ');
this.setState({passwordError:" Please fill in all fields! "})
}
}
}
export default seeker_login
另一个页面(导出类 View_Profile 扩展组件):
return (
<>
<View style={styles.container}>
<View style={styles.header}>
<Text>
{JSON.stringify(this.props.route.getparams.otherParam)}
</Text>
</View>
解决方案
推荐阅读
- javascript - 将 iOS 模块从 pod 导入到 nativescript 插件
- javascript - 从方法链的末尾获取不同的输出
- python-3.x - 在 AWS S3 存储桶中获取文件的标签
- android - Firebase 推送通知打开计数不起作用
- ruby-on-rails - Rails - 错误后我可以在视图中显示不同的部分吗?
- scala - 如何从 sql(不是 DSL)访问 Spark 嵌套结构字段
- r - 计算和显示 ggplot2::geom_density() 对象的峰值的最佳方法是什么?
- c++11 - FFMPEG中lineSize,width,height之间的关系
- javascript - 组件之间的关系
- ruby - Rspec:合并的单元测试!Ruby 哈希中的方法