Explain it simply
Navigation Basics (Stack Navigator), in plain language
React Navigation is the de facto standard navigation library for React Native apps — Stack Navigator manages screens as a 'stack' (piled one on top of another): navigating from screen A to B pushes B onto the stack, and the back button pops it off again (a familiar mobile navigation pattern). You move between screens with navigation.navigate('ScreenName') and go back with navigation.goBack().
Problem → Why → Solution
The problem — why this concept matters
Forgetting to wrap NavigationContainer at the root of App — navigation.navigate won't work
A common mistake
Trying to manually pass the navigation prop into a screen component without understanding how it gets there automatically (React Navigation provides it automatically)
Core concept — understand how it works
For Navigation Basics (Stack Navigator), separate ownership of navigation, form, server, and device state. Test rapid taps, back gestures, deep links, process restarts, keyboard use, and screen-reader flows.
- route or action
- navigator
- screen state
Explain the React and native-platform behavior of Navigation Basics (Stack Navigator)
Core syntax or pattern
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './HomeScreen';
import DetailScreen from './DetailScreen';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Detail" component={DetailScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
// Inside HomeScreen:
// <Button title="View Detail" onPress={() => navigation.navigate('Detail')} />For Navigation Basics (Stack Navigator), separate ownership of navigation, form, server, and device state. Test rapid taps, back gestures, deep links, process restarts, keyboard use, and screen-reader flows.
Read the code step by step
- route or action
import { NavigationContainer } from '@react-navigatio...React Navigation is the de facto standard navigation library for React Native apps — Stack Navigator manages screens as a 'stack' (piled one on top of another): navigating from screen A to B pushes B onto the stack, and the back button pops it off again (a familiar mobile navigation pattern). You move between screens with navigation.navigate('ScreenName') and go back with navigation.goBack().
- navigator
<Stack.Navigator>For Navigation Basics (Stack Navigator), separate ownership of navigation, form, server, and device state. Test rapid taps, back gestures, deep links, process restarts, keyboard use, and screen-reader flows.
- screen state
// <Button title="View Detail" onPress={() => navigat...Test an original Navigation Basics (Stack Navigator) example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
- route or action
- navigator
- screen state
Success
Explain the React and native-platform behavior of Navigation Basics (Stack Navigator)
Failure
Forgetting to wrap NavigationContainer at the root of App — navigation.navigate won't work
Let's think about this for a moment
React Navigation is the de facto standard navigation library for React Native apps — Stack Navigator manages screens as a 'stack' (piled one on top of another): navigating from screen A to B pushes B onto the stack, and the back button pops it off again (a familiar mobile navigation pattern). You move between screens with navigation.navigate('ScreenName') and go back with navigation.goBack().
Let's connect this to a real scenario
After installing npm install @react-navigation/native @react-navigation/native-stack, you wrap Stack.Navigator inside NavigationContainer — each screen gets registered as a Stack.Screen component (with a name prop + component prop). Calling navigation.navigate('ScreenB') from a button press on Screen A will transition to Screen B with an animation.
Code Example
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './HomeScreen';
import DetailScreen from './DetailScreen';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Detail" component={DetailScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
// Inside HomeScreen:
// <Button title="View Detail" onPress={() => navigation.navigate('Detail')} />Pressing a button on the Home screen navigates to the Detail screen with a transition animation.5-Minute Try-It
Create 2 screens (Home, Detail) and try connecting them with React Navigation's Stack Navigator.
A Quick Heads-Up
Writing navigation.navigate('WrongScreenName') won't cause a compile error but can crash at runtime — make sure the string inside navigate() exactly matches the Stack.Screen name prop.
Real-world usage
How to apply it in a real project
Test an original Navigation Basics (Stack Navigator) example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
Mini challenge
Build it yourself
Test an original Navigation Basics (Stack Navigator) example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './HomeScreen';
import DetailScreen from './DetailScreen';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Detail" component={DetailScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
// Inside HomeScreen:
// <Button title="View Detail" onPress={() => navigation.navigate('Detail')} />Expected: Explain the React and native-platform behavior of Navigation Basics (Stack Navigator)
Show hint
Test an original Navigation Basics (Stack Navigator) example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- route or action → navigator → screen state
- For Navigation Basics (Stack Navigator), separate ownership of navigation, form, server, and device state. Test rapid taps, back gestures, deep links, process restarts, keyboard use, and screen-reader flows.
- Forgetting to wrap NavigationContainer at the root of App — navigation.navigate won't work
- Test an original Navigation Basics (Stack Navigator) example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
React Native Documentation — React Native