我想在响应Native底部选项卡中加载仪表板作为活动选项卡。加载仪表板时导航,但每当我移动到仪表板时,它都会移动到收件箱屏幕,这是我的反应底部选项卡导航中的第一个元素。每当使用屏幕底部标签时,有没有办法创建默认屏幕?
我用于底部导航的代码是
dashboard: {
screen: createBottomTabNavigator({
inbox: {
screen: Chat,
navigationOptions: ({ navigation }) => ({
title: 'Inbox',
}),
},
favourite: {
screen: Favourite,
navigationOptions: ({ navigation }) => ({
title: 'Favourite',
}),
},
dashboard: {
screen: Dashboard,
navigationOptions: ({ navigation }) => ({
title: 'Home',
initialRouteName: 'dashboard'
}),
},
setting: {
screen: SettingScreen,
navigationOptions: ({ navigation }) => ({
title: 'Setting',
}),
},
survey: {
screen: NutritionistSurvey,
navigationOptions: ({ navigation }) => ({
title: 'Survey',
}),
},
}),
navigationOptions: ({ navigation }) => ({
title: 'Dashboard',
}),
},
即使导航工作完全正常,我只需要在用户导航到仪表板时加载仪表板屏幕。
您可以在createBottomTabNavigator中添加initialRouteName我将解决您的问题
const MyApp = createBottomTabNavigator(
{
Inbox: {
screen: Chat,
navigationOptions: ({ navigation }) => ({
title: "Inbox"
})
},
Favourite: {
screen: Favourite,
navigationOptions: ({ navigation }) => ({
title: "Favourite"
})
},
Dashboard: {
screen: Dashboard,
navigationOptions: ({ navigation }) => ({
title: "Home"
})
}
},
{
initialRouteName: "Dashboard"
}
);
您有2个名为dashboard的屏幕,bottomTabNavigator和Dashboard屏幕,因此当您尝试导航到仪表板时,react-navigation将导航到bottomTabNavigator的第一个选项卡。
重命名bottomTabNavigator,它应该工作:
dashboardTabs: {
screen: createBottomTabNavigator({
inbox: {
screen: Chat,
navigationOptions: ({ navigation }) => ({
title: 'Inbox',
}),
},
favourite: {
screen: Favourite,
navigationOptions: ({ navigation }) => ({
title: 'Favourite',
}),
},
dashboard: {
screen: Dashboard,
navigationOptions: ({ navigation }) => ({
title: 'Home',
initialRouteName: 'dashboard'
}),
},
setting: {
screen: SettingScreen,
navigationOptions: ({ navigation }) => ({
title: 'Setting',
}),
},
survey: {
screen: NutritionistSurvey,
navigationOptions: ({ navigation }) => ({
title: 'Survey',
}),
},
}),
navigationOptions: ({ navigation }) => ({
title: 'Dashboard',
}),
},