React Native Navigation: Stack vs. Tab vs. Drawer
On the web, navigation is handled by the browser's URL history. In mobile apps, we have to manage the navigation stack manually. The standard library for this is React Navigation.
Setting up navigation correctly is critical for User Experience (UX). Let's look at the three main types of navigators and when to use them.
Installation
React Navigation 6+ requires a few dependencies:
npm install @react-navigation/native
npm install react-native-screens react-native-safe-area-context
1. Stack Navigator
This is the most common form of navigation. Think of a deck of cards. When you open a new screen, you put a card on top. When you press "Back," you remove the top card to reveal the previous one.
Use Case: Drilling down into content. (e.g., Feed List -> Single Post Details -> User Profile).
import { createNativeStackNavigator } from '@react-navigation/native-stack';
const Stack = createNativeStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
);
}
2. Bottom Tab Navigator
This creates a persistent bar at the bottom of the screen.
Use Case: The top-level sections of your app. Think Instagram (Feed, Search, Reels, Shop, Profile).
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Feed" component={FeedScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
3. Drawer Navigator
A sidebar that slides in from the left, usually triggered by a "Hamburger" menu icon.
Use Case: Apps with many top-level destinations that don't fit in a bottom tab bar (e.g., Gmail folders). Note: Bottom Tabs are generally preferred over Drawers in modern UX design as they are easier to reach with a thumb.
The Power of Nesting
Real apps mix these together. You usually have a Tab Navigator as the main entry point, but each Tab is actually a Stack Navigator.
Example Structure:
* App (Tab Navigator)
* Tab 1: Home (Stack Navigator)
* Screen: Feed List
* Screen: Post Details
* Tab 2: Profile (Stack Navigator)
* Screen: Profile View
* Screen: Edit Profile
function HomeStackScreen() {
return (
<Stack.Navigator>
<Stack.Screen name="Feed" component={FeedScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeStackScreen} />
<Tab.Screen name="Profile" component={ProfileStackScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}
Conclusion
Choosing the right navigator defines how your user moves through the app. Use Tabs for high-level categorization, Stacks for detailed flows, and keep Drawers for secondary features.