|
| 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