From 1061562ef7c975fefa653014a02f2ad1960972ce Mon Sep 17 00:00:00 2001 From: Tien Pham <32733132+tienf4m@users.noreply.github.com> Date: Sun, 21 Jan 2018 03:37:24 +0700 Subject: [PATCH] Update goBack docs (#2834) * Update goBack docs * Update Screen-Navigation-Prop.md --- .../docs/guides/Navigation-Actions.md | 2 +- .../docs/guides/Screen-Navigation-Prop.md | 47 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/react-navigation/docs/guides/Navigation-Actions.md b/packages/react-navigation/docs/guides/Navigation-Actions.md index 35a7762d..5559c8fe 100644 --- a/packages/react-navigation/docs/guides/Navigation-Actions.md +++ b/packages/react-navigation/docs/guides/Navigation-Actions.md @@ -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' diff --git a/packages/react-navigation/docs/guides/Screen-Navigation-Prop.md b/packages/react-navigation/docs/guides/Screen-Navigation-Prop.md index 62e6450f..6acd7089 100644 --- a/packages/react-navigation/docs/guides/Screen-Navigation-Prop.md +++ b/packages/react-navigation/docs/guides/Screen-Navigation-Prop.md @@ -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 { />