Skip to content

Commit a9bc409

Browse files
committed
Document UNSTABLE_routeNamesChangeBehavior="lastUnhandled"
1 parent b24106d commit a9bc409

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

versioned_docs/version-7.x/auth-flow.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,65 @@ By specifying a condition for our screens, we can implement auth flow in a simpl
938938
## Don't manually navigate when conditionally rendering screens
939939

940940
It's important to note that when using such a setup, you **don't manually navigate** to the `Home` screen by calling `navigation.navigate('Home')` or any other method. **React Navigation will automatically navigate to the correct screen** when `isSignedIn` changes - `Home` screen when `isSignedIn` becomes `true`, and to `SignIn` screen when `isSignedIn` becomes `false`. You'll get an error if you attempt to navigate manually.
941+
942+
## Handling deep links after auth
943+
944+
When using deep links, you may want to handle the case where the user opens a deep link that requires authentication.
945+
946+
Example scenario:
947+
948+
- User opens a deep link to `myapp://profile` but is not signed in.
949+
- The app shows the `SignIn` screen.
950+
- After the user signs in, you want to navigate them to the `Profile` screen.
951+
952+
To achieve this, you can pass `UNSTABLE_routeNamesChangeBehavior="lastUnhandled"`:
953+
954+
:::warning
955+
956+
This option is experimental and may change in a minor release.
957+
958+
:::
959+
960+
<Tabs groupId="config" queryString="config">
961+
<TabItem value="static" label="Static" default>
962+
963+
```js
964+
const RootStack = createNativeStackNavigator({
965+
// highlight-next-line
966+
UNSTABLE_routeNamesChangeBehavior: 'lastUnhandled',
967+
screens: {
968+
Home: {
969+
if: useIsSignedIn,
970+
screen: HomeScreen,
971+
},
972+
SignIn: {
973+
if: useIsSignedOut,
974+
screen: SignInScreen,
975+
options: {
976+
title: 'Sign in',
977+
},
978+
},
979+
},
980+
});
981+
```
982+
983+
</TabItem>
984+
<TabItem value="dynamic" label="Dynamic">
985+
986+
```js
987+
<Stack.Navigator
988+
// highlight-next-line
989+
UNSTABLE_routeNamesChangeBehavior="lastUnhandled"
990+
>
991+
{isSignedIn ? (
992+
<Stack.Screen name="Home" component={HomeScreen} />
993+
) : (
994+
<Stack.Screen name="SignIn" component={SignInScreen} />
995+
)}
996+
</Stack.Navigator>
997+
```
998+
999+
</TabItem>
1000+
</Tabs>
1001+
1002+
The `UNSTABLE_routeNamesChangeBehavior` option allows you to control how React Navigation handles navigation when the available screens change because of conditions such as authentication state. When `lastUnhandled` is specified, React Navigation will remember the last screen that couldn't be handled, and after the condition changes, it'll automatically navigate to that screen if it's now available.

0 commit comments

Comments
 (0)