Created
November 16, 2018 14:58
-
-
Save srph/01f8ee068964ff882be3f717c5173b83 to your computer and use it in GitHub Desktop.
React Router v4: Passthrough props for Switch
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 { Switch } from 'react-router-dom' | |
interface IRouterSwitch { | |
children: any | |
} | |
class RouterSwitch extends React.Component<IRouterSwitch, {}> { | |
render() { | |
const {children, ...rest} = this.props | |
console.log('RouterSwitch', rest, children) | |
return ( | |
<Switch> | |
{React.Children.map(children, (child: any) => | |
React.cloneElement(child, rest) | |
)} | |
</Switch> | |
) | |
} | |
} | |
export default RouterSwitch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment