Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 71 ยท Navigation

Navigation Concepts for Mobile

Understand mobile navigation before you pick a library: the screen stack, tabs and drawers, deep links, React Navigation versus Expo Router, with live stand-ins.

A website has pages, and the browser gives you the address bar, the back button and history. A mobile app has screens, and nothing gives you navigation for free: React Native has no built-in router. You choose a navigation library, and to choose well you need the concepts first. Where does the back button go? Which screens stay alive when you switch tabs? What happens when someone taps a link that points deep inside your app?

This lesson explains the model that nearly every mobile app shares: a stack of screens, wrapped by tabs or a drawer, reachable through deep links. It then compares the two libraries you will most likely use, React Navigation and Expo Router. The next lessons build real navigators; here you learn what they do inside, with a tiny reducer you can run.

Read-only and stand-in. The navigation libraries need the native runtime, so their code appears in plain blocks. The TryIts implement the underlying idea (a state object changed by actions) in plain JavaScript and render it as HTML, so the rules are visible and testable. A real navigator adds animations, gestures, headers and native screen containers on top.

Screens as a history stack

The core idea is simple: navigation state is a stack, a list where you add and remove at the end. The last item is the screen the user sees. Moving forward pushes a screen, going back pops the top one, and the screens below stay alive underneath, so when you go back the previous screen is still exactly as you left it (scroll position, typed text).

TEXT
Push "Details"       Push "Reviews"        Back (pop)
[ Home ]             [ Home ]              [ Home ]
[ Home, Details ] -> [ Home, Details,  ] -> [ Home, Details ]
                       Reviews ]

The common actions are:

Action Effect on the stack
push(screen) Add a new screen on top, even if the same screen is already there
navigate(screen) Go to that screen: reuse it if it is already in the stack, otherwise add it
pop() / goBack() Remove the top screen
popToTop() Remove everything except the first screen
replace(screen) Swap the top screen for another one (no way back to the old one)
reset(routes) Replace the entire stack, used after logging in or out

replace and reset are how you stop users from going "back" into a login screen after signing in.

On iOS the back action is a swipe from the left edge or a button in the header. On Android it is the system back button or gesture (see Platform APIs for BackHandler). A good navigation library handles both, so your screens do not.

A stack of screens

Push Put a screen on top.
Pop Remove the top screen.
Replace Swap the top one.
Reset Start a new stack.

Screens below the top stay alive.

1 / 2

Stand-in: a stack reducer

Here is the idea in code. The navigation state is { routes: [...] }, and a pure function takes the state and an action and returns the next state (the same pattern as reducers). The page renders the stack and the top screen. Libraries keep a similar state object internally.

A navigation stack as a reducer

Try this sequence: push Details twice, then replace with Settings. The stack is ["Home","Details","Settings"]. Then navigate Home: because Home is already in the stack, everything above it is removed, whereas push would have added a second Home. Finally reset to Login: one screen, no back button, which is what you want after a logout.

Tabs and drawers

Most apps wrap several stacks in a higher-level navigator:

  • Bottom tabs show 2 to 5 top-level areas (Home, Search, Profile) with icons. They are the standard on both platforms. Each tab usually has its own stack, so tapping a tab returns you to where you were in that area, and tapping the active tab again typically scrolls up or pops to its first screen.
  • A drawer slides in from the side with a list of sections. It suits apps with many destinations, such as admin tools, and is less common on iOS.
  • Top tabs (swipeable) switch between related views in one screen, such as "Following" and "For you".

These navigators nest: a tab navigator contains stack navigators, which contain screens. The rule that surprises beginners: a screen can only navigate to screens in its own navigator or in a parent, unless you give the full path to a nested one. Nested navigators also each handle the back button in turn, from the innermost out.

There is one more layer you will often add: an authentication switch at the very top, deciding whether to show the login flow or the main tabs. That is covered in Deep Linking and Authentication Flows.

flowchart TD
    Root["Root navigator"] --> Auth["Auth stack<br/>(Login, Register)"]
    Root --> Main["Tabs (Home, Search, Profile)"]
    Main --> HomeStack["Home stack<br/>(Feed, Post)"]
    Main --> SearchStack["Search stack<br/>(Search, Result)"]
    Main --> ProfileStack["Profile stack<br/>(Profile, Settings)"]

A typical app: an auth stack or a tab bar at the root, with one stack inside each tab.

A deep link is a URL that opens your app on a specific screen: myapp://post/42 (a custom scheme) or https://example.com/post/42 (a universal link on iOS, an app link on Android). Links arrive from emails, notifications, web pages and other apps.

For a deep link to work, the navigation library needs a mapping from URL paths to screens, and it must build the right stack, not only the final screen. If a user opens /post/42 from a notification, pressing back should land on the feed, not close the app. The way you plan routes (stable paths, parameters in the URL) therefore affects your whole navigation design. The setup details come in the deep linking lesson; for now remember: every screen that could be a link target needs a URL.

The second stand-in has two tabs, each with its own stack, and a function that turns a URL into a state: which tab is active and which stack to build underneath it. Switching tabs keeps each tab's stack, as real tab navigators do.

Tabs with separate stacks and a URL resolver

Push two items on the home tab, switch to profile and back: the home stack is still there. Open /post/42: the tab switches to home and the stack becomes ["Feed","Post 42"], so Back lands on the feed. An unknown link falls back to the initial state instead of crashing, which a real app should do too.

React Navigation and Expo Router

Two libraries cover almost every React Native app, and they are closely related.

React Navigation is the long-standing, JavaScript-first library. You declare navigators and screens in code (createNativeStackNavigator, createBottomTabNavigator, createDrawerNavigator) and navigate with navigation.navigate('Details', { id: 42 }). It is explicit and flexible, and works in any React Native project, with or without Expo. You learn it in the next lessons, starting with Stack Navigation with React Navigation.

Expo Router is file-based routing built on top of React Navigation. Files in an app folder become screens, like in Next.js: app/index.tsx is the home screen, app/post/[id].tsx is a dynamic route, and _layout.tsx files define the stacks and tabs. Every screen gets a URL automatically, which makes deep links and web support almost free. You meet it in File-Based Routing with Expo Router.

React Navigation Expo Router
Routes defined by Code (navigators and screens) Files and folders
URLs for deep links You write a linking config Automatic from file paths
Works without Expo Yes Needs Expo's tooling
Learning curve Explicit, more setup Convention-based, less code

Since Expo Router uses React Navigation underneath, concepts like stacks, params and tabs carry over. Learning the concepts here and the React Navigation lessons gives you both. For a new Expo project, Expo Router is the common default; for an existing bare project or an app that needs full control, React Navigation is the standard.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. The stack is [Home, Details, Settings]. You call navigate('Home') in a stack that already contains Home. What is the result?

    navigate reuses an existing screen and removes the screens above it. push would have added a second Home.
  2. 2. After a successful login you want to stop users from going back to the login screen. What should you use?

    reset and replace remove the login screen from the history, so back cannot return to it.
  3. 3. Why does a deep link need to build a stack and not only show the target screen?

    A user who opens /post/42 expects Back to go to the feed. The library must create the screens beneath the target.
  4. 4. How does Expo Router relate to React Navigation?

    Expo Router maps files to routes and uses React Navigation navigators underneath, so the concepts carry over.

Summary

  • Mobile navigation is a stack of screens: push adds, pop removes, replace swaps and reset starts over; lower screens stay alive.
  • navigate reuses an existing screen, push always adds one.
  • Tabs and drawers wrap stacks; each tab usually owns its own stack, and navigators nest.
  • Deep links map URLs to screens and must build a sensible stack beneath the target.
  • React Navigation is code-defined and flexible; Expo Router is file-based and built on it, with automatic URLs.

Next, build a real stack in Stack Navigation with React Navigation.