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 flag | Value / default | Applies to | Source |
|---|---|---|---|
SessionProvider | Wrap the root navigator and every useSession consumer | Current Expo auth example | auth |
Slot / Stack | Render a Slot or other navigator on the first render; put blocking/loading decisions in a child | Root mount invariant | redirect guide |
Stack.Protected / guard | After loading, !!session for private screens and !session for sign-in | SDK 53+; current example | auth, introduction |
Redirect / href | href="/sign-in" only after nested loading has finished and session is absent | SDK 52 and earlier pattern | redirect guide |
SplashScreen.preventAutoHideAsync() / SplashScreen.hide() | Retain splash until isLoading is false; navigator still mounts beneath it | Current Expo auth example | auth |
Stack.Protected.redirectTo | Optional explicit destination such as /sign-in; otherwise accessible anchor/initial route, then first accessible route | SDK 58 | migration |
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) | Cause | Fix | Source |
|---|---|---|---|
Attempted to navigate before mounting the Root Layout component | Dispatch before root navigator exists | Mount root Slot/Stack; move conditional redirects down | guide, andrew-levy report |
useSession must be wrapped in a <SessionProvider /> | Auth hook is outside its provider | Put provider above hook consumers, including the root navigator component | auth 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