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-actions.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -282,7 +282,7 @@ In a stack navigator ([stack](stack-navigator.md) or [native stack](native-stack
282
282
283
283
- If you're already on a screen with the same name, it will update its params and not push a new screen.
284
284
- If you're on a different screen, it will push the new screen onto the stack.
285
-
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will navigate to that screen and update its params instead.
285
+
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/navigation-object.md
+2-37
Original file line number
Diff line number
Diff line change
@@ -248,40 +248,6 @@ In a stack navigator ([stack](stack-navigator.md) or [native stack](native-stack
248
248
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
249
249
- If none of the above conditions match, it'll push a new screen to the stack.
250
250
251
-
By default, the screen is identified by its name. But you can also customize it to take the params into account by using the [`getId`](screen.md#id) prop.
252
-
253
-
For example, say you have specified a `getId` prop for `Profile` screen:
254
-
255
-
<TabsgroupId="config"queryString="config">
256
-
<TabItemvalue="static"label="Static"default>
257
-
258
-
```js
259
-
constTabs=createBottomTabNavigator({
260
-
screens: {
261
-
Profile: {
262
-
screen: ProfileScreen,
263
-
getId: ({ params }) =>params.userId,
264
-
},
265
-
},
266
-
});
267
-
```
268
-
269
-
</TabItem>
270
-
<TabItemvalue="dynamic"label="Dynamic">
271
-
272
-
```js
273
-
<Tab.Screen
274
-
name={Profile}
275
-
component={ProfileScreen}
276
-
getId={({ params }) =>params.userId}
277
-
/>
278
-
```
279
-
280
-
</TabItem>
281
-
</Tabs>
282
-
283
-
Now, if you have a stack with the history `Home > Profile (userId: bob) > Settings` and you call `navigate(Profile, { userId: 'alice' })`, the resulting screens will be `Home > Profile (userId: bob) > Settings > Profile (userId: alice)` since it'll add a new `Profile` screen as no matching screen was found.
284
-
285
251
In a tab or drawer navigator, calling `navigate` will switch to the relevant screen if it's not focused already and update the params of the screen.
286
252
287
253
### `navigateDeprecated`
@@ -304,9 +270,8 @@ It takes the following arguments:
304
270
In a stack navigator ([stack](stack-navigator.md) or [native stack](native-stack-navigator.md)), calling `navigate` with a screen name will have the following behavior:
305
271
306
272
- If you're already on a screen with the same name, it will update its params and not push a new screen.
307
-
- If a screen with the same name already exists in the stack, it will pop all the screens after it to go back to the existing screen.
308
-
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will pop any screens to navigate to that screen and update its params instead.
309
-
- If none of the above conditions match, it'll push a new screen to the stack.
273
+
- If you're on a different screen, it will push the new screen onto the stack.
274
+
- If the [`getId`](screen.md#id) prop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
310
275
311
276
In a tab or drawer navigator, calling `navigate` will switch to the relevant screen if it's not focused already and update the params of the screen.
By default, `navigate('ScreenName', params)` updates the current screen if the screen name matches, otherwise adds a new screen in a stack navigator. So if you're on `ScreenName` and navigate to `ScreenName` again, it won't add a new screen even if the params are different - it'll update the current screen with the new params instead:
247
+
In the above example, `params.userId` is used as an ID for the `Profile`screen with `getId`. This changes how the navigation works to ensure that the screen with the same ID appears only once in the stack.
248
248
249
-
```js
250
-
// Let's say you're on `Home` screen
251
-
// Then you navigate to `Profile` screen with `userId: 1`
252
-
navigation.navigate('Profile', { userId:1 });
253
-
254
-
// Now the stack will have: `Home` -> `Profile` with `userId: 1`
255
-
256
-
// Then you navigate to `Profile` screen again with `userId: 2`
257
-
navigation.navigate('Profile', { userId:2 });
258
-
259
-
// The stack will now have: `Home` -> `Profile` with `userId: 2`
260
-
```
261
-
262
-
If you specify `getId` and it doesn't return `undefined`, the screen is identified by both the screen name and the returned ID. That means that if you're on `ScreenName` and navigate to `ScreenName` again with different params - and return a different ID from the `getId` callback, it'll add a new screen to the stack:
263
-
264
-
```js
265
-
// Let's say you're on `Home` screen
266
-
// Then you navigate to `Profile` screen with `userId: 1`
267
-
navigation.navigate('Profile', { userId:1 });
268
-
269
-
// Now the stack will have: `Home` -> `Profile` with `userId: 1`
270
-
271
-
// Then you navigate to `Profile` screen again with `userId: 2`
272
-
navigation.navigate('Profile', { userId:2 });
273
-
274
-
// The stack will now have: `Home` -> `Profile` with `userId: 1` -> `Profile` with `userId: 2`
275
-
```
276
-
277
-
The `getId` callback can also be used to ensure that the screen with the same ID doesn't appear multiple times in the stack:
278
-
279
-
```js
280
-
// Let's say you have a stack with the screens: `Home` -> `Profile` with `userId: 1` -> `Settings`
281
-
// Then you navigate to `Profile` screen with `userId: 1` again
282
-
navigation.navigate('Profile', { userId:1 });
283
-
284
-
// Now the stack will have: `Home` -> `Profile` with `userId: 1`
285
-
```
249
+
Let's say you have a stack with the history `Home > Profile (userId: bob) > Settings`, consider following scenarios:
286
250
287
-
In the above examples, `params.userId` is used as an ID, subsequent navigation to the screen with the same `userId` will navigate to the existing screen instead of adding a new one to the stack. If the navigation was with a different `userId`, then it'll add a new screen.
251
+
- You call `navigate(Profile, { userId: 'bob' })`:
252
+
The resulting screens will be `Home > Settings > Profile (userId: bob)` since the existing `Profile` screen matches the ID.
253
+
- You call `navigate(Profile, { userId: 'alice' })`:
254
+
The resulting screens will be `Home > Profile (userId: bob) > Settings > Profile (userId: alice)` since it'll add a new `Profile` screen as no matching screen was found.
288
255
289
256
If `getId` is specified in a tab or drawer navigator, the screen will remount if the ID changes.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/upgrading-from-6.x.md
+7-3
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,12 @@ The methods now behave as follows:
55
55
56
56
See [`popTo`](stack-actions.md#popto) for more details.
57
57
58
-
To achieve a behavior similar to before with `navigate`, you can use the [`getId`](screen.md#id) prop in which case it'll go to the screen with the matching ID and push or pop screens accordingly.
58
+
To achieve a behavior similar to before with `navigate`, you can use specify `pop: true` in the options:
To help with the migration, we have added a new method called `navigateDeprecated` which will behave like the old `navigate` method. You can replace your current `navigate` calls with [`navigateDeprecated`](navigation-object.md#navigatedeprecated) to gradually migrate to the new behavior:
61
66
@@ -80,8 +85,7 @@ It's problematic since:
80
85
- None of the other actions support such usage.
81
86
- Specifying a `key` is not type-safe, making it easy to cause bugs.
82
87
83
-
In React Navigation 5, we added the [`getId`](screen.md#id) prop which can be used for similar use cases - and gives users full control since they provide the ID and it's not autogenerated by the
84
-
library.
88
+
In React Navigation 5, we added the [`getId`](screen.md#id) prop which can be used for similar use cases - and gives users full control since they provide the ID and it's not autogenerated by the library.
85
89
86
90
So the `key` option is now being removed from the `navigate` action.
0 commit comments