Skip to content

Commit b8feddf

Browse files
authored
Merge pull request #3687 from reactjs/function-to-docs
Add docs for function to on <Link>
2 parents 1c72f23 + 372741f commit b8feddf

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/API.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ A `<Link>` can know when the route it links to is active and automatically apply
9494

9595
#### Props
9696
##### `to`
97-
A [location descriptor](https://github.com/ReactTraining/history/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
97+
A [location descriptor](https://github.com/ReactTraining/history/blob/master/docs/Glossary.md#locationdescriptor) or a function that takes the current location and returns a location descriptor. This location descriptor is usually a string or an object, with the following semantics:
9898

9999
* If it's a string it represents the absolute path to link to, e.g. `/users/123` (relative paths are not supported).
100100
* If it's an object it can have four keys:
@@ -105,6 +105,23 @@ A [location descriptor](https://github.com/ReactTraining/history/blob/master/doc
105105

106106
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to `hash`._
107107

108+
```jsx
109+
// String location descriptor.
110+
<Link to="/hello">
111+
Hello
112+
</Link>
113+
114+
// Object location descriptor.
115+
<Link to={{ pathname: '/hello', query: { name: 'ryan' } }}>
116+
Hello
117+
</Link>
118+
119+
// Function returning location descriptor.
120+
<Link to={location => ({ ...location, query: { name: 'ryan' } })}>
121+
Hello
122+
</Link>
123+
```
124+
108125
##### `activeClassName`
109126
The className a `<Link>` receives when its route is active. No active class by default.
110127

0 commit comments

Comments
 (0)