Skip to content

Instantly share code, notes, and snippets.

@srph
Created November 16, 2018 15:01
Show Gist options
  • Save srph/0678f4f565bcf0c2857d6a2c3d0c8288 to your computer and use it in GitHub Desktop.
Save srph/0678f4f565bcf0c2857d6a2c3d0c8288 to your computer and use it in GitHub Desktop.
React Router v4: Passthrough props Route
import * as React from 'react'
import { Route } from 'react-router-dom'
import { RouteProps } from 'react-router'
interface IRouterRouteProps extends RouteProps {
component: any
}
class RouterRoute extends React.Component<IRouterRouteProps> {
render() {
const { component, ...rest } = this.props
const Component = this.props.component
return (
<Route {...rest} render={(props) => <Component {...props} {...rest} />} />
)
}
}
export default RouterRoute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment