skip to content

In a mobile app's design, what does it mean to model navigation as state, a stack of routes, and what does it make possible?

level: juniorimportance: should knowfreq 38%

answer

  1. where the user is, as data
  2. name plus small arguments
  3. start destination at the bottom
  4. IDs in routes, never objects
  5. build, check, save, test

basics

~20 s

Navigation becomes an ordered stack of routes, each a destination name plus small arguments such as a listing ID, start destination at the bottom, visible screen on top. As plain data, it can be built, checked and saved by any entry point.

solid answer

~50 s

Treating navigation as state means the source of truth for *where the user is* is a list of route values, not a chain of screens that happened to open each other. Each route is a destination name plus the minimum needed to rebuild it, such as `listing(id = 123)`, never the listing object itself, which the screen loads from the data layer. The bottom entry is the app's fixed **start destination**, say the browse feed; sign-in and onboarding are conditional screens, not the start. Push, pop and replace are operations on that list, and the UI renders whatever is on top. That buys three things: a link, a notification tap or a resume after sign-in can each produce a whole stack and hand it over in one step; the stack can be validated before anything is shown; and it is small and serialisable, so it can be saved, logged and tested without drawing a screen.

go deeper

for a junior

Recall the shape: a back stack of routes, the start destination at the bottom, the visible screen on top, and routes that carry IDs rather than whole objects.

for a middle

Explain push, pop and replace as operations on data, and show how a link or notification tap becomes a whole stack built in one step instead of a chain of screen calls.

for a senior

Show the production payoff: one place that validates every entry point, stacks small enough to save and log with a crash, and navigation logic tested without rendering a screen.

for a principal

Frame the route model as a cross-team contract: route names and arguments become the vocabulary features, links and notifications share, so changing them is an interface change.

## The back stack as a value Every mobile app has a **back stack**: the ordered history of screens the user can step back through. The top of the stack is the screen on display; the entries beneath it are where the user came from. At the very bottom sits the **start destination**, the first screen a normal launch shows and the last one the user sees before leaving the app. In a second-hand marketplace app that is usually the browse feed. **Modelling navigation as state** means the app keeps that stack as an explicit piece of data that it owns, rather than letting it emerge from screens opening other screens. Each entry is a **route**: a destination name plus a few small arguments. The UI is then a function of the stack: whatever route is on top is what gets drawn. This is the same one-way data flow the rest of a well-layered client follows, applied to *where the user is* instead of *what the data is*. ## What a route holds A route carries only what is needed to rebuild its screen: | Route field | Good example | Why not more | |---|---|---| | Destination name | `listing`, `checkout`, `offer` | A name the whole app agrees on, not a screen reference | | Identifiers | `listingId = 123`, `offerId = 9` | The screen loads current data itself | | Small UI choices | which tab of the listing is open | Anything bigger belongs in the data layer | The rule *IDs, not objects* matters. A listing object copied into a route goes stale the moment the price changes, can be large, and couples the screen that sends it to the shape the screen that receives it expects. An ID keeps the **data layer** as the single source of truth: the destination asks for listing 123 and gets its current state. Some screens are **conditional**: sign-in, a first-run tour, a one-time setup. Users see them only in certain situations, so they are never the start destination. A signed-out user who opens the marketplace still lands on the browse feed; sign-in appears when something actually needs a session. ## Operations on the stack Changes to the stack are a short list of operations: - **push**: add a route on top (open a listing from the feed); - **pop**: remove the top route (back); - **replace**: swap the top route, or the whole stack, in one step (finish sign-in and put checkout where sign-in was; open a link and build a fresh stack); - **reset**: return to the start destination alone (sign out). Because every change goes through these operations, they can be logged, checked and replayed. A screen asks the navigation layer for a route; it does not construct the next screen itself. ## What it makes possible The value of treating navigation as data shows up at the app's **entry points**, the ways a user arrives somewhere other than the start destination: 1. **A link** to a listing can be turned into a complete stack, start destination underneath and listing on top, and installed in one step. 2. **A notification tap** for a new offer can be turned into a stack by the same code, so a tap and a link to the same thing behave identically. 3. **A sign-in gate** can hold the user's intended destination as a value, show sign-in, and resume that exact destination afterwards. 4. **Validation** happens before display: a malformed ID or an unknown route is caught while it is still data, and the app falls back to the start destination instead of showing a broken screen. 5. **Saving and testing** become cheap: a stack of names and IDs is small and serialisable, so it can be written to small saved state, logged with a crash report, or asserted in a unit test without drawing anything. ## Where this question stops Holding the stack as data is the foundation; several neighbouring concerns build on it and are designed elsewhere. Restoring a saved stack after the operating system kills the app in the background is part of the app's lifecycle design. The exact navigation component each platform or cross-platform framework offers, and its API, belongs to that platform's own material. Which module may depend on which, when features open each other's screens, belongs to the module-graph design. What stays here is the idea every one of them relies on: *the route stack is the state, and screens are drawn from it.*

  • Why should a listing route in a mobile app carry the listing's ID rather than the listing object?
    An object copied into a route is a second copy of the data: it goes stale when the price or status changes, it can be large to save, and it ties the sending screen to the receiving screen's model. An ID keeps the data layer as the single source of truth; the destination loads listing 123 and shows its current state. Links and notifications only carry IDs anyway, so every entry point works the same way.
  • Is the sign-in screen the start destination of a marketplace app whose checkout needs a session?
    No. Sign-in is a conditional screen: users meet it only when something needs a session. The start destination stays the browse feed, which is the first screen of a normal launch and the last before leaving the app. Sign-in is shown over the stack when a gated route is requested, then removed once it succeeds.

  • Navigation is just screens opening screens; there is no state worth designing.
  • A route should carry the whole listing object so the next screen skips a fetch.
  • Sign-in is the start destination because signed-out users meet it first.
  • Each screen should decide by itself which screens sit beneath it.
  • The navigation stack cannot be validated before it is shown to the user.