|
| 1 | +Primary component of React Router. It keeps your UI and the URL in sync. |
| 2 | + |
| 3 | +## Props |
| 4 | +----- |
| 5 | + |
| 6 | +#### `children` (required) |
| 7 | + |
| 8 | +One or many [`Routes`][Route] or [Plain Routes][PlainRoute]. When the |
| 9 | +history changes, `Router` will match a branch of its [`Routes`][Route], |
| 10 | +and render their configured [components][RouteComponent], with child |
| 11 | +route components nested inside the parents. |
| 12 | + |
| 13 | +#### `routes` |
| 14 | + |
| 15 | +Alias for `children`. |
| 16 | + |
| 17 | +#### `history` |
| 18 | + |
| 19 | +The history the router should listen to from the `history` package. |
| 20 | + |
| 21 | +#### `createElement(Component, props)` |
| 22 | + |
| 23 | +When the router is ready to render a branch of route components, it will |
| 24 | +use this function to create the elements. You may want to take control |
| 25 | +of creating the elements when you're using some sort of data |
| 26 | +abstraction, like setting up subscriptions to stores, or passing in some |
| 27 | +sort of application module to each component via props. |
| 28 | + |
| 29 | +##### Examples |
| 30 | + |
| 31 | +```js |
| 32 | +<Router createElement={createElement}/> |
| 33 | + |
| 34 | +// default behavior |
| 35 | +function createElement(Component, props) { |
| 36 | + // make sure you pass all the props in! |
| 37 | + return <Component {...props}/> |
| 38 | +} |
| 39 | + |
| 40 | +// maybe you're using something like Relay |
| 41 | +function createElement(Component, props) { |
| 42 | + // make sure you pass all the props in! |
| 43 | + return <RelayContainer Component={Component} routerProps={props}/>; |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +#### `stringifyQuery(queryObject)` |
| 48 | + |
| 49 | +A function used to convert an object from `Link`s or calls to |
| 50 | +`transitionTo` to a URL query string. |
| 51 | + |
| 52 | +#### `parseQueryString(queryString)` |
| 53 | + |
| 54 | +A function used to convert a query string into an object that gets |
| 55 | +passed to route component props. |
| 56 | + |
| 57 | +#### `onError(error)` |
| 58 | + |
| 59 | +While the router is matching, errors may bubble up, here |
| 60 | +is your opportunity to catch and deal with them. Typically these will |
| 61 | +come from async features like `route.getComponents` and |
| 62 | +`route.getChildRoutes`. |
| 63 | + |
| 64 | +### `onUpdate()` |
| 65 | + |
| 66 | +Called whenever the router updates its state in response to URL changes. |
| 67 | + |
| 68 | +Examples |
| 69 | +-------- |
| 70 | + |
| 71 | +Please see the `examples/` directory of the repository for extensive |
| 72 | +exampls of using `Router`. |
| 73 | + |
0 commit comments