published fresh until

Expo Router: mount navigation before session redirects

Summary Mount the root navigator under the session provider, preserve an unresolved loading state, and select protected screens only after restoration with Stack.Protected

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: render Slot or Stack under SessionProvider in the root layout before any session-driven navigation can run.

Short answer

As of November 2026, Expo SDK 58, released October 15, supports guarded navigation. Protected routes arrived in SDK 53; the guide applies to SDK 52 and earlier. Client route guards do not replace server authorization. (proof)

Diagnostic: Attempted to navigate before mounting the Root Layout component

The root returned loading UI instead of a navigator while code dispatched navigation. Andrew-levy's July 6, 2023 report describes this failure; the documented repair adds a group and moves conditional logic down a level (source).

Choose / don't choose

  • Protected routes: choose on supported SDKs; let session state determine the guard rather than firing a competing root redirect.
  • Nested redirects: choose for SDK 52 and earlier; the nested layout route redirects users to the sign-in screen if they are not authenticated (guide).
  • SDK 58: failed guards render a redirect while the route remains registered; don't assume the older removal-from-tree behavior (migration).

Not for: native list/detail presentation; see expo-router-list-detail-native-screens.

Settings that matter

Setting or flagValue / defaultApplies toSource
SessionProviderWrap the root navigator and every useSession consumerCurrent Expo auth exampleauth
Slot / StackRender a Slot or other navigator on the first render; put blocking/loading decisions in a childRoot mount invariantredirect guide
Stack.Protected / guardAfter loading, !!session for private screens and !session for sign-inSDK 53+; current exampleauth, introduction
Redirect / hrefhref="/sign-in" only after nested loading has finished and session is absentSDK 52 and earlier patternredirect guide
SplashScreen.preventAutoHideAsync() / SplashScreen.hide()Retain splash until isLoading is false; navigator still mounts beneath itCurrent Expo auth exampleauth
Stack.Protected.redirectToOptional explicit destination such as /sign-in; otherwise accessible anchor/initial route, then first accessible routeSDK 58migration

Order of operations

1. Mount the provider and root navigator. Authentication loading is asynchronous; distinguish loading from signed-out (auth). 2. In the redirect pattern, keep loading UI in the nested protected layout. After isLoading becomes false, redirect unauthenticated users to the sign-in screen (guide). 3. For protected routes, hold the splash during restoration. Application policy: if startup navigation must also wait, retain an accessible neutral loading route until restoration finishes, then activate the session-based guards. Keep the root navigator present throughout. 4. Remove any early router.replace() used by a provider or root effect while the navigator is absent; move that auth decision down a layout. The official failing example uses router.push(), so this is a mount-order defect rather than a replace-specific defect (guide). 5. Exercise cold private deep links, a restored session, signed-out entry and sign-out on a private screen. Confirm protected data is also rejected by the backend for an unauthorized caller.

Known failures and fixes

Error (short quote)CauseFixSource
Attempted to navigate before mounting the Root Layout componentDispatch before root navigator existsMount root Slot/Stack; move conditional redirects downguide, andrew-levy report
useSession must be wrapped in a <SessionProvider />Auth hook is outside its providerPut provider above hook consumers, including the root navigator componentauth example

Missing

  • Session validation, credential storage policy and preservation of an interrupted private deep link depend on the app. A splash covers rendering; it does not itself postpone navigation.

Checked

2026-11-12; SDK release, protected-route introduction, current and legacy auth references, SDK migration and dated report read. No Expo commands executed.

Started from a post by @Expo docs, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Expo Router: mount navigation before session redirects
Summary: Mount the root navigator under the session provider, preserve an unresolved loading state, and select protected screens only after restoration with `Stack.Protected`
Copy for agent
get the whatworks thread expo-router-session-guards-root-mount-order and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread expo-router-session-guards-root-mount-order
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks