Skip to content

Commit 5a8fdc8

Browse files
committed
Document navigator specific state
1 parent 3f2a62f commit 5a8fdc8

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

versioned_docs/version-7.x/navigation-state.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ const state = {
6969

7070
It's important to note that even if there's a nested navigator, the `state` property on the `route` object is not added until a navigation happens, hence it's not guaranteed to exist, or maybe [stale](#stale-state-objects).
7171

72+
## Navigator specific state
73+
74+
Various navigators may also add additional properties to the navigation state object. Each navigator uses a [router](custom-routers.md) to manage the navigation state, and the router determines the shape of the navigation state object.
75+
76+
Built-in navigators add the following properties:
77+
78+
### Stack
79+
80+
For navigators using the built-in `StackRouter`, such as [Stack](stack-navigator.md) and [Native Stack](native-stack-navigator.md) navigators, the state object has the following additional properties:
81+
82+
- `type` - Always `stack`.
83+
- `preloadedRoutes` - Route objects for stack screens preloaded with [`preload`](navigation-actions.md#preload).
84+
85+
### Tab
86+
87+
For navigators using the built-in `TabRouter`, such as [Bottom Tabs](bottom-tab-navigator.md) and [Material Top Tabs](material-top-tab-navigator.md) navigators, the state object has the following additional properties:
88+
89+
- `type` - Always `tab`.
90+
- `history` - Route history entries with `{ type: 'route', key, params? }`.
91+
- `preloadedRouteKeys` - Route keys for tab screens preloaded with [`preload`](navigation-actions.md#preload).
92+
93+
### Drawer
94+
95+
For navigators using the built-in `DrawerRouter`, such as [Drawer](drawer-navigator.md) navigator, the state object contains the same properties as the `TabRouter` with the following additional properties:
96+
97+
- `type` - Always `drawer`.
98+
- `default` - The default drawer status from the `defaultStatus` option, either `open` or `closed`.
99+
- `history` - Drawer entries with `{ type: 'drawer', status: 'open' | 'closed' }` in addition to route history entries.
100+
72101
## History stack
73102

74103
In React Navigation, each navigator may maintain a history stack to keep track of visited entries. This is used when navigating back, syncing with browser history on the Web, etc.

versioned_docs/version-8.x/navigation-state.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ const state = {
7070

7171
It's important to note that even if there's a nested navigator, the `state` property on the `route` object is not added until a navigation happens, hence it's not guaranteed to exist, or maybe [stale](#stale-state-objects).
7272

73+
## Navigator specific state
74+
75+
Various navigators may also add additional properties to the navigation state object. Each navigator uses a [router](custom-routers.md) to manage the navigation state, and the router determines the shape of the navigation state object.
76+
77+
Built-in navigators add the following properties:
78+
79+
### Stack
80+
81+
For navigators using the built-in `StackRouter`, such as [Stack](stack-navigator.md) and [Native Stack](native-stack-navigator.md) navigators, the state object has the following additional properties:
82+
83+
- `type` - Always `stack`.
84+
- `retainedRouteKeys` - Route keys for routes that should be [retained](stack-actions.md#retain) when they are removed from the history stack.
85+
86+
The `routes` array contains the history of visited screens until `index`, and the route objects after `index` represent [preloaded](navigation-actions.md#preload) or [retained](stack-actions.md#retain) screens.
87+
88+
### Tab
89+
90+
For navigators using the built-in `TabRouter`, such as [Bottom Tabs](bottom-tab-navigator.md) and [Material Top Tabs](material-top-tab-navigator.md) navigators, the state object has the following additional properties:
91+
92+
- `type` - Always `tab`.
93+
- `history` - Route history entries with `{ type: 'route', key, params? }`.
94+
- `preloadedRouteKeys` - Route keys for tab screens preloaded with [`preload`](navigation-actions.md#preload).
95+
96+
### Drawer
97+
98+
For navigators using the built-in `DrawerRouter`, such as [Drawer](drawer-navigator.md) navigator, the state object contains the same properties as the `TabRouter` with the following additional properties:
99+
100+
- `type` - Always `drawer`.
101+
- `default` - The default drawer status from the `defaultStatus` option, either `open` or `closed`.
102+
- `history` - Drawer entries with `{ type: 'drawer', status: 'open' | 'closed' }` in addition to route history entries.
103+
73104
## History stack
74105

75106
In React Navigation, each navigator may maintain a history stack to keep track of visited entries. This is used when navigating back, syncing with browser history on the Web, etc.
@@ -78,7 +109,7 @@ Unlike Web, which has a linear history stack, React Navigation uses a nested his
78109

79110
The history stack for a navigator is determined from the following sources:
80111

81-
- `state.history` if present, otherwise `state.routes`
112+
- `state.history` if present, otherwise `state.routes` until `state.index`
82113
- `route.history` for each route in `state.routes`
83114

84115
When determining total length of history stack (e.g. to sync with browser history on the Web), these 2 sources are combined.

0 commit comments

Comments
 (0)