3
votes

I am trying to navigate to a specific tab from a screen, as the below code shows, I want to navigate to Tab2 from Screen1

Bottom Tabs

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

    })

Stack Navigator:

const AppNavigator = createStackNavigator(
  {

  BottomTabNavigator,
  Screen1,
  Screen2,
  Screen3 
  }
);

I tried the below but as expected it does navigate to the initial route which is Tab1

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

this.props.navigation.dispatch(resetAction);
1
Have you tried NavigationActions.navigate({ routeName: 'Tab2' })Zaytri

1 Answers

1
votes

You can set action on the NavigationAction.navigate's input object in order to also define the tab route.

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

or in your case

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