Skip to content

Commit b39e012

Browse files
committed
added DefaultRoute documentation
1 parent 8e6bb2e commit b39e012

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

docs/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ React Router API
44
- [`Router`](/docs/api/Router.md)
55

66
- Components
7+
- [`DefaultRoute`](/docs/api/components/DefaultRoute.md)
78
- [`Link`](/docs/api/components/Link.md)
89
- [`Redirect`](/docs/api/components/Redirect.md)
910
- [`Route`](/docs/api/components/Route.md)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
API: `DefaultRoute` (component)
2+
===============================
3+
4+
A route that is active when the parent route's path matches exactly. Or,
5+
in other words, the default child route for a parent.
6+
7+
Note, this is not a `NotFoundRoute`. It is only active when the parent's
8+
route path is matched exactly.
9+
10+
Props
11+
-----
12+
13+
### `handler`
14+
15+
The component to be rendered when the route is active.
16+
17+
### `preserveScrollPosition`
18+
19+
If `true`, the router will not scroll the window up when the route is
20+
transitioned to. Defaults to `false`. Ignored if the parent `<Routes/>`
21+
has been set to `true`.
22+
23+
Example
24+
-------
25+
26+
```xml
27+
<Routes>
28+
<Route path="/" handler={App}>
29+
30+
<!--
31+
when the url is `/`, this handler will be active, or in other
32+
words, will be `this.props.activeRouteHandler in the `App` handler
33+
-->
34+
<DefaultRoute handler={Home}/>
35+
36+
<Route name="about" handler={About}/>
37+
<Route name="users" handler={Users}>
38+
<Route name="user" handler={User} path="/user/:id"/>
39+
40+
<!-- when the url is `/users`, this will be active -->
41+
<DefaultRoute handler={UsersIndex}/>
42+
43+
</Route>
44+
</Route>
45+
</Routes>
46+
```
47+
48+
This is all really just a shortcut for the less intuitive version of the
49+
same functionality:
50+
51+
```xml
52+
<!-- no path or name on what was previously the "users" route -->
53+
<Route handler={Users}>
54+
<!-- the path moved down to the child -->
55+
<Route name="users-index" path="/users" handler={UsersIndex}/>
56+
<Route name="user" handler={User} path="/user/:id"/>
57+
</Route>
58+
```
59+
60+
`DefaultRoute` feels more natural, so you can name and transition to the
61+
parent route.
62+

0 commit comments

Comments
 (0)