mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-13 22:30:41 +08:00
Update goBack docs (#2834)
* Update goBack docs * Update Screen-Navigation-Prop.md
This commit is contained in:
@@ -80,7 +80,7 @@ this.props.navigation.dispatch(resetAction)
|
||||
### Back
|
||||
|
||||
Go back to previous screen and close current screen. `back` action creator takes in one optional parameter:
|
||||
- `key` - *string or null* - optional - If set, navigation will go back from the given key. If null, navigation will go back anywhere.
|
||||
- `key` - *string or null* - optional - If set, navigation will go back from the given key. If null, navigation will go back from the currently active route.
|
||||
|
||||
```js
|
||||
import { NavigationActions } from 'react-navigation'
|
||||
|
||||
@@ -90,7 +90,30 @@ class ProfileScreen extends React.Component {
|
||||
|
||||
## `goBack` - Close the active screen and move back
|
||||
|
||||
Optionally provide a key, which specifies the route to go back from. By default, goBack will close the route that it is called from. If the goal is to go back *anywhere*, without specifying what is getting closed, call `.goBack(null);`
|
||||
Optionally provide a key, which specifies the route to go back from. By default, goBack will close the route that it is called from.
|
||||
|
||||
*Going back from a specific screen*
|
||||
|
||||
Consider the following navigation state:
|
||||
```
|
||||
{
|
||||
routes: [
|
||||
{ routeName: 'HomeScreen', key: 'A' },
|
||||
{ routeName: 'DetailScreen', key: 'B' },
|
||||
{ routeName: 'DetailScreen', key: 'C' },
|
||||
],
|
||||
index: 2
|
||||
}
|
||||
```
|
||||
|
||||
Now you are on *screen C* and want to go back to the *HomeScreen (A)* (popping C and B).
|
||||
Then you need to supply a key to goBack *FROM*:
|
||||
|
||||
```
|
||||
navigation.goBack("B") // will go to screen A FROM screen B
|
||||
```
|
||||
|
||||
If the goal is to go back from the currently active route, call `.goBack(null);`
|
||||
|
||||
```js
|
||||
class HomeScreen extends React.Component {
|
||||
@@ -104,7 +127,7 @@ class HomeScreen extends React.Component {
|
||||
/>
|
||||
<Button
|
||||
onPress={() => goBack(null)}
|
||||
title="Go back anywhere"
|
||||
title="Go back from the currently active route"
|
||||
/>
|
||||
<Button
|
||||
onPress={() => goBack('screen-123')}
|
||||
@@ -116,26 +139,6 @@ class HomeScreen extends React.Component {
|
||||
}
|
||||
```
|
||||
|
||||
*Going back from a specific screen*
|
||||
|
||||
Consider the following navigation stack history:
|
||||
```...
|
||||
navigation.navigate(SCREEN_KEY_A);
|
||||
...
|
||||
navigation.navigate(SCREEN_KEY_B);
|
||||
...
|
||||
navigation.navigate(SCREEN_KEY_C);
|
||||
...
|
||||
navigation.navigate(SCREEN_KEY_D);
|
||||
```
|
||||
|
||||
Now you are on *screen D* and want to go back to *screen A* (popping D, C, and B).
|
||||
Then you need to supply a key to goBack *FROM*:
|
||||
|
||||
```
|
||||
navigation.goBack(SCREEN_KEY_B) // will go to screen A FROM screen B
|
||||
```
|
||||
|
||||
## `dispatch` - Send an action to the router
|
||||
|
||||
Use dispatch to send any navigation action to the router. The other navigation functions use dispatch behind the scenes.
|
||||
|
||||
Reference in New Issue
Block a user