Valentyn Vynogradskiy
Valentyn Vynogradskiy

Reputation: 653

React Navigation Reset Stack Navigator which is sub navigation

I have a TabNavigator which is created by createBottomTabNavigator

createBottomTabNavigator({
    Tab1: View1,
    Tab2: createStackNavigator({
        SubScreen1: View2,
        SubScreen2: View3
    }),
    Tab3: createStackNavigator({
        SubScreen3: View4,
        SubScreen4: View5,
        SubScreen5: View6
    }),

})

And now lets say i'm on Tab3, doing some stuff on SubScreen3 then press next, the same for SubScreen4, next, And now i'm on Tab3/SubScreen5 and i want to this.props.navigation.navigate('Subscreen 2') which is working fine, but when i go to Tab3 again it is still on SubScreen5.

What is want is to reset Tab3 back to SubScreen3 every time i go to some other tab.

I've tried to

navigation.dispatch(
    StackActions.reset(
      {
          index:0, 
          actions:[NavigationActions.navigate('SubScreen2')]
       })
);

But that didn't work.

Upvotes: 0

Views: 236

Answers (1)

mcssym
mcssym

Reputation: 944

I think it is because SubScreen2 is not in the stack yet. Try this.

navigation.dispatch(
    StackActions.reset(
      {
          index:0, 
          key: null,
          actions:[NavigationActions.navigate({
              routeName: 'Tab2',
              action: NavigationActions.navigate({routeName: 'SubScreen2'})
          })]
       })
);

Upvotes: 1

Related Questions