Last active
September 9, 2018 08:39
-
-
Save mjackson/afa9d4f0f8e8225fd3e878606532f394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using createRouteElement | |
import { Route, createRouteElement } from 'react-router' | |
const RouteWithQuery = (routeProps) => ( | |
<Route {...routeProps} render={props => ( | |
const query = parseQueryString(props.history.location.search) | |
return createRouteElement({ ...routeProps, ...props, query }) | |
)}/> | |
) | |
// using Route.render | |
import { Route } from 'react-router' | |
const RouteWithQuery = (routeProps) => ( | |
<Route {...routeProps} render={props => ( | |
const query = parseQueryString(props.history.location.search) | |
return Route.render({ ...routeProps, ...props, query }) | |
)}/> | |
) | |
// using <Route getExtraProps> | |
import { Route } from 'react-router' | |
const RouteWithQuery = (props) => ( | |
<Route {...props} getExtraProps={({ history }) => ({ | |
query: parseQueryString(history.location.search) | |
})}/> | |
) | |
/* | |
The signature for <Route getExtraProps> is ({ match, history }) => props | |
where the resulting props are merged in with the props that are passed | |
to the component. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment