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/navigation-state.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,35 @@ const state = {
69
69
70
70
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).
71
71
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
+
72
101
## History stack
73
102
74
103
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.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/navigation-state.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,37 @@ const state = {
70
70
71
71
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).
72
72
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
+
73
104
## History stack
74
105
75
106
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
78
109
79
110
The history stack for a navigator is determined from the following sources:
80
111
81
-
-`state.history` if present, otherwise `state.routes`
112
+
-`state.history` if present, otherwise `state.routes` until `state.index`
82
113
-`route.history` for each route in `state.routes`
83
114
84
115
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