Thuta Learning
React Native
IntermediateMobile DevelopmentIntermediate

Navigation Basics (Stack Navigator)

React NativeLesson 1120 min

What you'll walk away with

  • Explain the React and native-platform behavior of Navigation Basics (Stack Navigator)
  • Test accessibility, failure, and lifecycle cases
  • Write maintainable, testable, and performant React Native

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.

Mental model
  1. route or action
  2. navigator
  3. screen state

Explain the React and native-platform behavior of Navigation Basics (Stack Navigator)

Core syntax or pattern

javascript
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

  1. route or actionimport { 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().

  2. 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.

  3. 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.

Execution flow
  1. route or action
  2. navigator
  3. 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

javascript
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')} />
You should see
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
javascript
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

What best describes the core idea of Navigation Basics (Stack Navigator)?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

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

Easy traps

  • Forgetting to wrap NavigationContainer at the root of App — navigation.navigate won't work
  • Trying to manually pass the navigation prop into a screen component without understanding how it gets there automatically (React Navigation provides it automatically)
  • Assuming one simulator's happy path proves every real-device, release-build, permission, accessibility, offline, and lifecycle path.

Hands-on Exercise

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.

You'll know it worked when: Pressing a button on the Home screen navigates to the Detail screen with a transition animation.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Navigation Basics (Stack Navigator) | Thuta Learning