Passing props to React Router children routes

后端 未结 3 899
时光说笑
时光说笑 2020-12-08 20:27

I\'m having trouble overcoming an issue with react router. The scenario is that i need to pass children routes a set of props from a state parent component and route.
wh

3条回答
  •  失恋的感觉
    2020-12-08 20:48

    React.cloneElement can be used to render the child component and so as pass any data which is available inside the child route component which is defined in the route.

    For eg, here I am passing the value of user to the react childRoute component.

    {React.cloneElement(this.props.childRoute, { user: this.props.user })}
    

提交回复
热议问题