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/navigating.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ On Android, React Navigation hooks in to the hardware back button and fires the
133
133
134
134
:::
135
135
136
-
Another common requirement is to be able to go back _multiple_ screens -- for example, if you are several screens deep in a stack and want to dismiss all of them to go back to the first screen. In this case, we know that we want to go back to `Home` so we can use `navigate('Home')` (not `push`! try that out and see the difference). Another alternative would be `navigation.popToTop()`, which goes back to the first screen in the stack.
136
+
Another common requirement is to be able to go back _multiple_ screens -- for example, if you are several screens deep in a stack and want to dismiss all of them to go back to the first screen. In this case, we know that we want to go back to `Home` so we can use `popTo('Home')`. Another alternative would be `navigation.popToTop()`, which goes back to the first screen in the stack.
137
137
138
138
<sampid="pop-to-top" />
139
139
@@ -146,7 +146,7 @@ function DetailsScreen({ navigation }) {
146
146
title="Go to Details... again"
147
147
onPress={() =>navigation.push('Details')}
148
148
/>
149
-
<Button title="Go to Home" onPress={() =>navigation.navigate('Home')} />
149
+
<Button title="Go to Home" onPress={() =>navigation.popTo('Home')} />
@@ -162,5 +162,5 @@ function DetailsScreen({ navigation }) {
162
162
-`navigation.navigate('RouteName')` pushes a new route to the native stack navigator if it's not already in the stack, otherwise it jumps to that screen.
163
163
- We can call `navigation.push('RouteName')` as many times as we like and it will continue pushing routes.
164
164
- The header bar will automatically show a back button, but you can programmatically go back by calling `navigation.goBack()`. On Android, the hardware back button just works as expected.
165
-
- You can go back to an existing screen in the stack with `navigation.navigate('RouteName')`, and you can go back to the first screen in the stack with `navigation.popToTop()`.
165
+
- You can go back to an existing screen in the stack with `navigation.popTo('RouteName')`, and you can go back to the first screen in the stack with `navigation.popToTop()`.
166
166
- The `navigation` prop is available to all screen components (components defined as screens in route configuration and rendered by React Navigation as a route).
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/navigation-actions.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,8 @@ The library exports several action creators under the `CommonActions` namespace.
23
23
24
24
The `navigate` action allows to navigate to a specific route. It takes the following arguments:
25
25
26
-
-`name` - _string_ - A destination name of the route that has been registered somewhere..
27
-
-`key` - _string_ - The identifier for the route to navigate to. Navigate back to this route if it already exists..
28
-
-`params` - _object_ - Params to merge into the destination route..
29
-
30
-
The options object passed should at least contain a `key` or `name` property, and optionally `params`. If both `key` and `name` are passed, stack navigator will create a new route with the specified key if no matches were found.
26
+
-`name` - _string_ - A destination name of the screen in the current or a parent navigator.
27
+
-`params` - _object_ - Params to use for the destination route.
31
28
32
29
<sampid="common-actions" />
33
30
@@ -44,9 +41,18 @@ navigation.dispatch(
44
41
);
45
42
```
46
43
47
-
In a [stack navigator](stack-navigator.md), calling `navigate` with a screen name will result in different behavior based on if the screen is already present or not. If the screen is already present in the stack's history, it'll go back to that screen and remove any screens after that. If the screen is not present, it'll push a new screen.
44
+
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:
45
+
46
+
- If you're already on a screen with the same name, it will update its params and not push a new screen.
47
+
- If you're on a different screen, it will push the new screen onto the stack.
48
+
- If the [`getId`](screen.md#getid) prop is specified, and another screen in the stack has the same ID, it will navigate to that screen and update its params instead.
49
+
50
+
The `navigate` action can also accepts an object as the argument with the following properties:
48
51
49
-
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#getid) prop.
52
+
-`name` - _string_ - A destination name of the screen in the current or a parent navigator
53
+
-`params` - _object_ - Params to use for the destination route.
54
+
-`merge` - _boolean_ - Whether we should merge the params of the current route with the provided `params`. Defaults to `false`.
55
+
-`path` - _string_ - The path (from deep link or universal link) to associate with the screen.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/navigation-prop.md
+5-22Lines changed: 5 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@ If the navigator is a stack navigator, several alternatives to `navigate` and `g
30
30
-`replace` - replace the current screen with a new one
31
31
-`push` - push a new screen onto the stack
32
32
-`pop` - go back in the stack
33
+
-`popTo` - go back to a specific screen in the stack
33
34
-`popToTop` - go to the top of the stack
34
35
35
36
See [Stack navigator helpers](stack-navigator.md#helpers) and [Native Stack navigator helpers](native-stack-navigator.md#helpers) for more details on these methods.
In a [native stack navigator](native-stack-navigator.md), calling `navigate` with a screen name will result in different behavior based on if the screen is already present or not. If the screen is already present in the stack's history, it'll go back to that screen and remove any screens after that. If the screen is not present, it'll push a new screen.
86
+
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:
86
87
87
-
For example, if you have a stack with the history `Home > Profile > Settings` and you call `navigate(Profile)`, the resulting screens will be `Home > Profile` as it goes back to `Profile` and removes the `Settings` screen.
88
+
- If you're already on a screen with the same name, it will update its params and not push a new screen.
89
+
- If you're on a different screen, it will push the new screen onto the stack.
90
+
- If the [`getId`](screen.md#getid) prop is specified, and another screen in the stack has the same ID, it will navigate to that screen and update its params instead.
88
91
89
92
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#getid) prop.
The `popTo` action takes you back to a previous screen in the stack by the name. It also allows you to pass params to the route.
82
+
83
+
If a matching screen is not found in the stack, this will pop the current screen and add a new screen with the specified name and params. This behavior is useful when the screen was opened from a deep link etc. and a previous screen with the name may or may not already be in the stack.
84
+
85
+
The method accepts the following arguments:
86
+
87
+
-`name` - _string_ - Name of the route to navigate to.
88
+
-`params` - _object_ - Screen params to pass to the destination route.
89
+
90
+
If a matching screen is not found in the stack, this will pop the current screen and add a new screen with the specified name and params. This behavior is useful when the screen was opened from a deep link and a previous screen with the name may or may not already be in the stack.
The `popToTop` action takes you back to the first screen in the stack, dismissing all the others. It's functionally identical to `StackActions.pop({n: currentIndex})`.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/upgrading-from-6.x.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ The `navigationInChildEnabled` prop will be removed in the next major.
37
37
38
38
Previously, `navigate` method navigated back if the screen already exists in the stack. We have seen many people get confused by this behavior.
39
39
40
-
To avoid this confusion, we have removed the going back behavior from `navigate` and added a new method `popTo` to explicitly go back to a specific screen in the stack:
40
+
To avoid this confusion, we have removed the going back behavior from `navigate` and added a [new method `popTo`](stack-actions.md#popto) to explicitly go back to a specific screen in the stack:
0 commit comments