You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/navigator.md
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -383,3 +383,81 @@ The function passed to `UNSTABLE_router` **must be a pure function and cannot re
383
383
The overrides object is shallow merged with the original router. So you don't need to specify all properties of the router, only the ones you want to override.
384
384
385
385
See [custom routers](custom-routers.md) for more details on routers.
386
+
387
+
### Route names change behavior
388
+
389
+
:::warning
390
+
391
+
This API is experimental and may change in a minor release.
392
+
393
+
:::
394
+
395
+
When the list of available routes in a navigator changes dynamically, e.g. based on conditional rendering, looping over data from an API etc., the navigator needs to update the [navigation state](navigation-state.md) according to the new list of routes.
396
+
397
+
By default, it works as follows:
398
+
399
+
- Any routes not present in the new available list of routes are removed from the navigation state
400
+
- If the currently focused route is still present in the new available list of routes, it remains focused.
401
+
- If the currently focused route has been removed, but the navigation state has other routes that are present in the new available list, the first route in from the list of rendered routes becomes focused.
402
+
- If none of the routes in the navigation state are present in the new available list of routes, one of the following things can happen based on the `UNSTABLE_routeNamesChangeBehavior` prop:
403
+
-`'firstMatch'` - The first route defined in the new list of routes becomes focused. This is the default behavior based on [`getStateForRouteNamesChange`](custom-routers.md#getstateforroutenameschange) in the router.
404
+
-`'lastUnhandled'` - The last state that was unhandled due to conditional rendering is restored.
405
+
406
+
Example cases where state might have been unhandled:
407
+
408
+
- Opened a deep link to a screen, but a login screen was shown.
409
+
- Navigated to a screen containing a navigator, but a different screen was shown.
410
+
- Reset the navigator to a state with different routes not matching the available list of routes.
411
+
412
+
In these cases, specifying `'lastUnhandled'` will reuse the unhandled state if present. If there's no unhandled state, it will fallback to `'firstMatch'` behavior.
413
+
414
+
Caveats:
415
+
416
+
- Direct navigation is only handled for `NAVIGATE` actions.
417
+
- Unhandled state is restored only if the current state becomes invalid, i.e. it doesn't contain any currently defined screens.
The most common use case for this is to [show the correct screen based on authentication based on deep link](auth-flow.md#handling-deep-links-after-auth).
0 commit comments