Created
November 16, 2018 15:01
-
-
Save srph/0678f4f565bcf0c2857d6a2c3d0c8288 to your computer and use it in GitHub Desktop.
React Router v4: Passthrough props Route
This file contains hidden or 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
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