Skip to content

Commit e37e17c

Browse files
SHIRSH ZIBBUtimdorr
authored andcommitted
Updates documentation of Switch, NavLink, Route (remix-run#5136)
* Updates documentation of Switch, missing prop location * Updates documentation of NavLink, missing prop location * Updates documentation of Route, missing prop location * Updates documentation of Switch, location property override for matching child * Updates documentation of Switch, NavLink, Route: reduce verbosity * Updates documentation of NavLink: fix broken link
1 parent cc7cad4 commit e37e17c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/react-router-dom/docs/api/NavLink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ const oddEvent = (match, location) => {
7474
isActive={oddEvent}
7575
>Event 123</NavLink>
7676
```
77+
78+
## location: object
79+
80+
The [`isActive`](#isactive-func) compares the current history location (usually the current browser URL).
81+
To compare to a different location, a [`location`](../../../react-router/docs/api/location.md) can be passed.

packages/react-router/docs/api/Route.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ When `true`, will only match if the path matches the `location.pathname` _exactl
148148
<Route exact path="/one" component={About}/>
149149
```
150150

151-
| path | location.pathname | exact | matches? |
152-
| --- | --- | --- | --- |
153-
| `/one` | `/one/two` | `true` | no |
154-
| `/one` | `/one/two` | `false` | yes |
151+
| path | location.pathname | exact | matches? |
152+
| --- | --- | --- | --- |
153+
| `/one` | `/one/two` | `true` | no |
154+
| `/one` | `/one/two` | `false` | yes |
155155

156156
## strict: bool
157157

@@ -178,3 +178,12 @@ When `true`, a `path` that has a trailing slash will only match a `location.path
178178
| `/one` | `/one` | yes |
179179
| `/one` | `/one/` | no |
180180
| `/one` | `/one/two` | no |
181+
182+
## location: object
183+
184+
A `<Route>` element tries to match its `path` to the current history location (usually the current browser URL).
185+
However, a [`location`](location.md) with a different `pathname` can also be passed for matching.
186+
187+
This is useful in cases when you need to match a `<Route>` to a location other than the current history location, as shown in the [Animated Transitions](https://reacttraining.com/react-router/web/example/animated-transitions) example.
188+
189+
If a `<Route>` element is wrapped in a `<Switch>` and matches the location passed to the `<Switch>` (or the current history location), then the `location` prop passed to `<Route>` will be overridden by the one used by the `<Switch>` (given [here](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Switch.js#L51)).

packages/react-router/docs/api/Switch.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@ This is also useful for animated transitions since the matched `<Route>` is rend
4848
a bit more cumbersome to work out */}
4949
</Fade>
5050
```
51+
## Switch props
5152

52-
## children: node
53+
### location: object
54+
55+
A [`location`](location.md) object to be used for matching children elements instead of the current history location (usually the current browser URL).
56+
57+
### children: node
5358

5459
All children of a `<Switch>` should be `<Route>` or `<Redirect>` elements. Only the first child to match the current location will be rendered.
5560

5661
`<Route>` elements are matched using their `path` prop and `<Redirect>` elements are matched using their `from` prop. A `<Route>` with no `path` prop or a `<Redirect>` with no `from` prop will always match the current location.
5762

5863
When you include a `<Redirect>` in a `<Switch>`, it can use any of the `<Route>`'s location matching props: `path`, `exact`, and `strict`. `from` is just an alias for the `path` prop.
5964

65+
If a `location` prop is given to the `<Switch>`, it will override the `location` prop on the matching child element.
66+
6067
```js
6168
<Switch>
6269
<Route exact path="/" component={Home}/>

0 commit comments

Comments
 (0)