我想通过主屏幕中的按钮点击操作将路径参数发送到“配置文件”选项卡。下面的代码是tab navigator
const Tabs = TabNavigator({
[routes.HOME]: {
screen: FeedMainScreen,
navigationOptions: {
tabBarLabel: tabBarLabels.HOME_TAB_LABEL,
},
},
[routes.SEARCH]: {
screen: SearchScreen,
navigationOptions: {
tabBarLabel: tabBarLabels.SEARCH_TAB_LABEL,
},
},
[routes.PROFILE]: {
screen: ProfileScreen,
navigationOptions: {
tabBarLabel: tabBarLabels.PROFILE_TAB_LABEL,
},
},
}
和按钮点击导航就像这样
<Button onPress={() => this.props.navigation.navigate(routes.PROFILE, { id: this.props.user._id }, null)} />
并在“个人资料”屏幕中按照此
来收集参数constructor (props) {
super(props)
console.log('NavPrams', this.props.navigation.state)
}
alwaya undifined
答案 0 :(得分:0)
您可以使用connect()方法成功映射道具并在任何地方使用它们。 在编写的类中添加下面提到的代码 -
const mapStateToProps = state => {
return {
user: this.props.user;
};
};
export default connect(mapStateToProps, {})(className);