React-Router:除了props.children,我可以将额外的变量传递给父级吗?

时间:2016-07-26 07:31:23

标签: reactjs react-router

如果我的路由器中有以下内容:

<Route path="/" component={MainLayout}>
    <Route path="path/one" component={App1} hasTitle={false} />
    <Route path="path/two" component={App2} hasTitle={true} />
</Route>

我将App1中的App2MainLayout作为this.props.children。但是我可以在MainLayout中进行一些其他自定义,例如,在上面的子路径中传递hasTitle=falsehasTitle=true吗?

1 个答案:

答案 0 :(得分:0)

使用cloneElement将其他道具传递给孩子,而不是{this.props.children}写入MainLayout

{React.cloneElement(this.props.children, {hasTitle:true})}
相关问题