Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-router-config - renderRoutes(routes, otherProps = {}) #5137

Merged
merged 5 commits into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/react-router-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ import routes from './routes'

Again, that's all pseudo-code. There are a lot of ways to do server rendering with data and pending navigation and we haven't settled on one. The point here is that `matchRoutes` gives you a chance to match statically outside of the render lifecycle. We'd like to make a demo app of this approach eventually.

### `renderRoutes(routes)`
### `renderRoutes(routes, otherProps = {})`

In order to ensure that matching outside of render with `matchRoutes` and inside of render result in the same branch, you must use `renderRoutes` instead of `<Route>` inside your components. You can render a `<Route>` still, but know that it will not be accounted for in `matchRoutes` outside of render.

Expand Down Expand Up @@ -225,13 +225,14 @@ const Child = ({ route }) => (
<div>
<h2>Child</h2>
{/* child routes won't render without this */}
{renderRoutes(route.routes)}
{renderRoutes(route.routes, { someProp: 'these extra props are optional' })}
</div>
)

const GrandChild = () => (
const GrandChild = ({ someProp }) => (
<div>
<h3>Grand Child</h3>
<div>{someProp}</div>
</div>
)

Expand Down
4 changes: 2 additions & 2 deletions packages/react-router-config/modules/renderRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react'
import Switch from 'react-router/Switch'
import Route from 'react-router/Route'

const renderRoutes = (routes) => routes ? (
const renderRoutes = (routes, otherProps = {}) => routes ? (
<Switch>
{routes.map((route, i) => (
<Route key={i} path={route.path} exact={route.exact} strict={route.strict} render={(props) => (
<route.component {...props} route={route}/>
<route.component {...props} {...otherProps} route={route}/>
)}/>
))}
</Switch>
Expand Down