12

I have 3 tabs and each tab contains a set of stack navigators.

  1. Home Stack
const HomeNavigator = createStackNavigator();

const HomeStackNavigator = ({ navigation, route }) => {
    return (
        <HomeNavigator.Navigator>
            <HomeNavigator.Screen
                name="Home"
                component={Home}
            />
            <HomeNavigator.Screen
                name="Profile"
                component={Profile}
            />
            <HomeNavigator.Screen
                name="Settings"
                component={Settings}
            />
        </HomeNavigator.Navigator>
    );
};

  1. Store Stack
const StoreNavigator = createStackNavigator();

const StoreStackNavigator = ({ navigation, route }) => {
    return (
        <StoreNavigator.Navigator>
            <StoreNavigator.Screen
                name="OurStore"
                component={Store}
            />
        </StoreNavigator.Navigator>
    );
};

  1. Community Stack
const CommunityNavigator = createStackNavigator();

const CommunityStackNavigator = ({ navigation, route }) => {
    return (
        <CommunityNavigator.Navigator>
            <CommunityNavigator.Screen
                name="Community"
                component={Community}
            />
            <CommunityNavigator.Screen
                name="CommunityReply"
                component={CommunityReply}
                options={communityReplyOptions}
            />
            <CommunityNavigator.Screen
                name="AskCommunity"
                component={AskCommunity}
            />
        </CommunityNavigator.Navigator>
    );
};

Tab Navigator

const MainNavigator = createBottomTabNavigator();

const MainTabNavigator = () => {
    return (
        <MainNavigator.Navigator
            screenOptions={tabScreenOptions}
            tabBarOptions={tabBarOptions}
        >
            <MainNavigator.Screen
                name="HomeTab"
                component={HomeStackNavigator}
                options={{ tabBarLabel: "Home" }}
            />
            <MainNavigator.Screen
                name="StoreTab"
                component={StoreStackNavigator}
                options={{ tabBarLabel: "Store" }}
            />
            <MainNavigator.Screen
                name="CommunityTab"
                component={CommunityStackNavigator}
                options={{ tabBarLabel: "Community" }}
            />
        </MainNavigator.Navigator>
    );
};

Now Home tab when a button clicked I need to navigate to CommunityReply Screen inside Community Tab Navigator. Can some please help me with this

Package versions

  • @react-navigation/bottom-tabs": "^5.8.0
  • @react-navigation/native": "^5.7.3
  • @react-navigation/stack": "^5.9.0

2 Answers 2

56

The below should work in this case:

navigation.navigate('CommunityTab', { screen: 'CommunityReply' });
Sign up to request clarification or add additional context in comments.

3 Comments

Do you know how to do it with navigation.reset? I was doing it like this, but it didn't work. this.props.navigation.reset({ index: 0, routes: [{name: 'CommunityTab', screen: 'CommunityReply'}], })
And if you need send params to screen use navigation.navigate('CommunityTab', { screen: 'CommunityReply', params: {key: 'value'}});
0

can use this:

const jumpToAction = TabActions.jumpTo('CommunityReply'); 
navigation.dispatch(jumpToAction);
navigation.navigate('CommunityTab');

2 Comments

Cannot find name TabActions ? where do i import it from
import { TabActions } from '@react-navigation/native'; try this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.