在导航选项上定义状态时出错
Error when defining a state on navigation options
我正在尝试使用 library 来启用本地化。在示例应用程序中,当我单击按钮时,出现错误:
Unhandled JS Exception: `title` cannot be defined as a function in navigation options for `Settings` screen.
Try replacing the following:
{
title: ({ state }) => state...
}
with:
({ navigation }) => ({
title: navigation.state...
})
我不确定问题出在什么时候,但我认为这是代码的和平
const AppNavigator = StackNavigator({
Home: {
screen: WelcomeContainer,
navigationOptions: {
title: 'Multi Language Sample App' // we advice using something static like your app's name or company name on the startup screen
}
},
Settings: {
screen: SettingsContainer,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
},
About:{
screen: About,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
}
})
我尝试用建议的代码替换代码,但没有成功。你能帮我解决问题吗?
react-navigation StackNavigator title
prop 需要一个字符串值。
title
String that can be used as a fallback for headerTitle
. Additionally, will be used as a fallback for tabBarLabel (if nested in
a TabNavigator
) or drawerLabel
(if nested in a DrawerNavigator
)
如果你想动态设置标题,你可以尝试实现下面的代码。
Settings: {
screen: SettingsContainer,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
}
我正在尝试使用 library 来启用本地化。在示例应用程序中,当我单击按钮时,出现错误:
Unhandled JS Exception: `title` cannot be defined as a function in navigation options for `Settings` screen.
Try replacing the following:
{
title: ({ state }) => state...
}
with:
({ navigation }) => ({
title: navigation.state...
})
我不确定问题出在什么时候,但我认为这是代码的和平
const AppNavigator = StackNavigator({
Home: {
screen: WelcomeContainer,
navigationOptions: {
title: 'Multi Language Sample App' // we advice using something static like your app's name or company name on the startup screen
}
},
Settings: {
screen: SettingsContainer,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
},
About:{
screen: About,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
}
})
我尝试用建议的代码替换代码,但没有成功。你能帮我解决问题吗?
react-navigation StackNavigator title
prop 需要一个字符串值。
title
String that can be used as a fallback for
headerTitle
. Additionally, will be used as a fallback for tabBarLabel (if nested in aTabNavigator
) ordrawerLabel
(if nested in aDrawerNavigator
)
如果你想动态设置标题,你可以尝试实现下面的代码。
Settings: {
screen: SettingsContainer,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
}