Skip to content

Commit 254a7b6

Browse files
authored
Merge pull request react-navigation#115 from react-navigation/@vonovak/key-docs
Key docs
2 parents 78bdec2 + f646dc6 commit 254a7b6

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

docs/navigation-key.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
id: navigation-key
3+
title: Using the navigation key
4+
sidebar_label: Using the navigation key
5+
---
6+
7+
The `key` parameter comes up repeatedly across different navigation functions. Let's take a look at a summary of its use cases:
8+
9+
### Usage with the [`navigate`](/docs/navigation-actions.html#navigate) call
10+
11+
If no key is provided, `StackRouter` will behave as follows:
12+
13+
* if a route with the given name already exists in the state, `StackRouter` will jump to the existing route, along with setting the new parameters.
14+
* if no such route exists, `StackRouter` will push it onto the stack
15+
16+
If, however, you want to push several instances of the same route, you can do so by providing a unique `key` parameter each time you call `navigate`, or you can use the `push` action available on `StackRouter`. See the related [RFC](https://github.com/react-navigation/rfcs/blob/master/text/0004-less-pushy-navigate.md) for more background.
17+
18+
> Note: the behavior of `navigate` without a `key` is significantly different in the 1.x series of releases. Read more about it [here](https://gist.github.com/vonovak/ef72f5efe1d36742de8968ff6a708985).
19+
20+
### Usage with [`reset`](/docs/navigation-actions.html#reset)
21+
22+
When resetting, `key` is also optional and can be a string or `null`. If set, the navigator with the given key will reset. If `null`, the root navigator will reset. You can obtain a route's navigator key by calling `this.props.navigation.dangerouslyGetParent().state.key`. Reason why the function is called `dangerouslyGetParent` is to warn developers against overusing it to eg. get parent of parent and other hard-to-follow patterns.
23+
24+
### Usage with [`replace`](/docs/navigation-actions.html#replace)
25+
26+
With the `replace` navigation action, `key` is a required parameter used for identifying the route to be replaced. If you use the helper function `this.props.navigation.replace`, we will automatically substitute the key of the current route.
27+
28+
### Usage with `goBack`
29+
30+
Please refer to the [`goBack docs`](/docs/navigation-prop.html#goback-close-the-active-screen-and-move-back) for a detailed explanation.

website/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
"Moving between screens": "Moving between screens",
7272
"navigation-actions": "NavigationActions reference",
7373
"NavigationActions": "NavigationActions",
74+
"navigation-key": "Using the navigation key",
75+
"Using the navigation key": "Using the navigation key",
7476
"navigation-options": "navigation-options",
7577
"Configuring Navigation Options": "Configuring Navigation Options",
7678
"navigation-prop": "Navigation prop reference",

website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"deep-linking",
2626
"screen-tracking",
2727
"state-persistence",
28-
"redux-integration"
28+
"redux-integration",
29+
"navigation-key"
2930
],
3031
"Build your own Navigator": [
3132
"custom-navigator-overview",

0 commit comments

Comments
 (0)