Skip to content

Instantly share code, notes, and snippets.

@mjackson
Last active September 9, 2018 08:39
Show Gist options
  • Save mjackson/afa9d4f0f8e8225fd3e878606532f394 to your computer and use it in GitHub Desktop.
Save mjackson/afa9d4f0f8e8225fd3e878606532f394 to your computer and use it in GitHub Desktop.
// 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