Skip to content

Lesson 6 of 9 · 26m

Navigation Is Application Architecture

Use React Navigation deliberately: stacks, tabs, deep links, auth gating, type safety, and state restoration without route spaghetti.

Navigation is where mobile architecture stops being theoretical. A route is not just a screen; it is lifecycle, permissions, data dependencies, back behavior, deep-link state, analytics identity, and the shape of the user's mental map. Teams that treat navigation as wiring end up with modals that cannot deep-link, auth redirects that fight the back button, and five copies of the same detail screen.

Model the app as state machines, not a pile of screens

A typical app has loading/bootstrap, unauthenticated auth, authenticated main tabs, blocking states such as force upgrade, and modal workflows nested inside authenticated context. Do not implement auth by rendering a login component over arbitrary screens. Route the user into a different navigation tree when the session is absent, expired, or unverified.

Type the routes

With React Navigation, type parameter lists and use typed navigation helpers:

export type RootStackParamList = {
  Auth: undefined
  MainTabs: undefined
  OrderDetail: {orderId: string}
  Scanner: {returnTo: 'OrderDetail' | 'Inventory'}
}

Type safety does not prevent bad UX, but it forces you to decide what identity a route actually needs. Passing huge objects through params duplicates truth; pass IDs and let a controlled cache resolve the entity.

A deep link is untrusted input. Validate IDs, enforce authentication and authorization, and handle missing or deleted objects:

export const linking = {
  prefixes: ['myapp://', 'https://app.example.com'],
  config: {
    screens: {
      OrderDetail: 'orders/:orderId',
      Settings: 'settings',
    },
  },
}

The route orders/abc must not assume the user can read that order. Navigation is never authorization.

Back behavior and tabs are product behavior

Android hardware back, gesture navigation, iOS swipe back, and nested navigators expose weak mental models. Decide whether submitting a form replaces the route, pops it, or resets the stack:

navigation.reset({index: 0, routes: [{name: 'MainTabs'}]})

Each tab commonly keeps its own stack. That means a detail screen under Orders is not the same as a detail screen under Search, even if the component is shared. Users expect each tab to preserve context. Use shared components, not forced global routes, unless the product truly wants one canonical path.

Restoration and instrumentation need restraint

Persisting navigation state improves continuity, but restore is not always appropriate. If a user was in payment confirmation, account switch, or one-time onboarding, blindly restoring can bypass required transitions. Instrument stable semantic screen names for analytics, support reproduction, performance traces, and crash context.

Field notes

  • Universal links and Android App Links require platform verification files and signing alignment; custom schemes are easier but less trustworthy.
  • Test deep links cold start, warm start, logged out, wrong tenant, revoked access, and deleted object cases.
  • Nested navigate calls are a smell when a declarative route config would express the transition.
  • Screen17 is not a screen name; future support staff cannot reproduce what they cannot name.

Was this lesson helpful?

Sign in to rate