React Native BottomTabs导航到特定选项卡

时间:2019-03-28 14:50:41

标签: react-native react-navigation

我试图从屏幕上导航到特定选项卡,如以下代码所示,我想从Screen1导航到Tab2

底部标签

const BottomTabNavigator = createBottomTabNavigator({
    Tab1,
    Tab2},
  {
    initialRouteName: 'Tab1',

    })

Stack Navigator:

const AppNavigator = createStackNavigator(
  {

  BottomTabNavigator,
  Screen1,
  Screen2,
  Screen3 
  }
);

我尝试了以下操作,但正如预期的那样,它确实导航到了Tab1的初始路径

const resetAction = StackActions.reset({index: 0,               
actions: [NavigationActions.navigate({ routeName: 'BottomTabNavigator', }),],});

this.props.navigation.dispatch(resetAction);

1 个答案:

答案 0 :(得分:1)

您可以在action的输入对象上设置NavigationAction.navigate,以同时定义制表符路由。

NavigationActions.navigate({
  routeName: 'BottomTabNavigator',
  action: NavigationActions.navigate({
    routeName: 'Tab2'
 })
})

或者您的情况

const resetAction = StackActions.reset({
  index: 0,               
  actions: [
    NavigationActions.navigate(
      routeName: 'BottomTabNavigator',
      action: NavigationActions.navigate({
        routeName: 'Tab2'
      })
    )
  ]
});