通过react-router v4将props传递给子组件
Passing props to children components with react-router v4
前情回顾。*我通过
将props传递给子组件React.cloneElement(this.props.children, this.props)
在react-router v4中如何使用新的<Match />
API
到目前为止,我想出的解决方案是在<Match />
API中使用render
方法:
<Match pattern="/" render={() => <ChildComponent {...this.props} />} />
使用ES6的扩展语法将props传递给子组件。是否有一个更好的方式,也携带它所有的标准道具(位置,模式,路径名,isExact)到子组件?
根据v4.0.0-alpha5的呈现代码判断,您有以下两个选项:
<Match pattern="/" render={props => <ChildComponent {...props} {...this.props} />} />
<Match pattern="/">{({matched, ...props}) => {
return matched ? <ChildComponent {...props} {...this.props} /> : null;
}}</Match>
相关文章:
- 在 React 中嵌套组件,props 不会传递给子组件
- 通过“;类“"实例”;使用ReactJS组件代替“props”文字
- React Redux 子组件获取父组件设置的全局属性,而无需通过 props 传递它
- 如何将数据从子组件获取到 props 中传递的按钮的 onclick 中
- 如何处理 React 0.12+ 中的组件引用变量和 props
- 丢弃传递给 React 组件的 rest-props 是一个错误吗?
- 对React Native中从父组件传下来的props数组进行更改
- 通过react-router v4将props传递给子组件
- React-router:将props传递给es6处理器组件
- react-router是如何通过props传递参数给其他组件的?
- 如何使用单个文件组件传递Props ?
- 我可以更新React.js中的组件's props吗?
- 我可以在react组件的父组件中设置子组件的props吗?
- React的子组件有未定义的props.style
- 有了reactjs和react-router,我可以显示一个组件或者{this.props.children}吗?
- 从props中初始化组件状态
- React:将props传递给函数组件
- 如何在组件的Javascript eval中传递props
- React:如何给库中的组件添加一个props
- 子组件不会在setState之后使用新的props进行更新