Javascript 未在标头中获取参数
我没有在主(homeStack)屏幕中将参数设置到我的标题 当我使用Home:{screen:Home}而不是Home:{screen:homeStack}更改CreateBoottomTabNavigator时,参数会在该屏幕中成功传输到我的标题。我不知道为什么会这样。请帮助我将该用户数据获取到主屏幕的标题中 此外,我希望在每个选项卡中都有一个不同的标题,并且我希望通过params向标题显示数据,我将其作为登录名输入: navigation.navigate('Home',{user:user}) My app.js代码:Javascript 未在标头中获取参数,javascript,react-native,react-navigation,Javascript,React Native,React Navigation,我没有在主(homeStack)屏幕中将参数设置到我的标题 当我使用Home:{screen:Home}而不是Home:{screen:homeStack}更改CreateBoottomTabNavigator时,参数会在该屏幕中成功传输到我的标题。我不知道为什么会这样。请帮助我将该用户数据获取到主屏幕的标题中 此外,我希望在每个选项卡中都有一个不同的标题,并且我希望通过params向标题显示数据,我将其作为登录名输入: navigation.navigate('Home',{user:user
const homeStack = createStackNavigator({
screen1: {
screen: Home,
navigationOptions: {
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
},
},
},{ initialRouteName: 'screen1'});
const Routes = createStackNavigator({
Login: {
screen: Login,
navigationOptions: {
header: null,
}
},
Main: {
screen: createBottomTabNavigator({
Home: { screen: homeStack },
Profile: { screen: Settings },
}, {
initialRouteName:'Home',
})
}
},{
initialRouteName: 'Login',
});
export default class App extends React.Component {
render() {
return (
<Routes />
);
}
}
const homeStack=createStackNavigator({
屏幕1:{
屏幕:主页,
导航选项:{
头型:{
背景颜色:“#F451E”,
},
标题颜色:“#fff”,
头饰样式:{
fontWeight:'粗体',
},
},
},
},{initialRouteName:'screen1'});
const Routes=createStackNavigator({
登录:{
屏幕:登录,
导航选项:{
标题:null,
}
},
主要内容:{
屏幕:CreateBoottomTabNavigator({
主页:{screen:homeStack},
配置文件:{屏幕:设置},
}, {
initialRouteName:“主页”,
})
}
},{
initialRouteName:'登录',
});
导出默认类App扩展React.Component{
render(){
返回(
);
}
}
主屏幕中的代码,其中为标题:
export default class Home extends React.Component {
static navigationOptions = ({ navigation, navigationOptions }) => {
console.log(navigationOptions);
console.log(navigation);
// Notice the logs ^
// sometimes we call with the default navigationOptions and other times
// we call this with the previous navigationOptions that were returned from
// this very function
/*return {
title: navigation.getParam('user', 'A Nested Details Screen'),
headerStyle: {
backgroundColor: navigationOptions.headerTintColor,
},
headerTintColor: navigationOptions.headerStyle.backgroundColor,
headerTitle: navigation.state.params.user.name,
}; */
return {
headerTitle: navigation.state.params.user.name,
}
};
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
</View>
);
}
}
导出默认类Home.Component{
静态导航选项=({navigation,navigationOptions})=>{
console.log(导航选项);
控制台日志(导航);
//注意日志^
//有时我们使用默认的navigationOptions调用,有时则使用默认的navigationOptions调用
//我们将其与以前从返回的navigationOptions一起称为
//这正是功能所在
/*返回{
标题:navigation.getParam('user','A Nested Details Screen'),
头型:{
背景颜色:导航选项。标题颜色,
},
HeaderIntColor:navigationOptions.headerStyle.backgroundColor,
标题:navigation.state.params.user.name,
}; */
返回{
标题:navigation.state.params.user.name,
}
};
render(){
返回(
打开App.js开始使用你的应用程序!
您所做的更改将自动重新加载。
摇动手机以打开开发者菜单。
);
}
}
问题解决了吗?我用另一种方式解决了。。。