0
votes

The example on React Navigation shows how you can jump to a tab, but it shows it in the case you are in the navigator the tabs are part of. But how do you navigate to a specific tab from a screen which is part of a different navigator?

I have:

function MealsNavigator() {
  const MealsStack = createStackNavigator();
  return (
    <MealsStack.Navigator>
      <MealsStack.Screen
        name="Meals"
        component={MealsScreenTabs}
      />
    </MealsStack.Navigator>
  );
}

function MealsScreenTabs() {
  const MealsTabs = createMaterialTopTabNavigator();
  return (
    <MealsTabs.Navigator>
      <MealsTabs.Screen name="Upcoming" component={MealsUpcomingScreen} />
      <MealsTabs.Screen name="Past" component={MealsPastScreen} />
    </MealsTabs.Navigator>
  );
}

I want to be able to navigate to Meals > Past with a button click from my Profile screen inside the Account navigator. How?

2
Can you write here the nesting of your screens? where is the Account navigator? - Yoel
The tabs are in the Meals navigator, why is it important to look at the Account navigator? - Ben

2 Answers

0
votes

in react navigation v5

navigation.navigate('Meals', {screen: 'Past'});

0
votes

Got some help from the community on Discord. Here' how you do it:

navigation.navigate('Meals', {
  screen: 'Meals',
  params: {screen: 'Past'},
})

And to see it in action, have a look at a snack I created