阵营父将数据发送到多个孩子
问题描述:
我有具有上述结构,其中父具有侧边栏和呈现两个孩子一个反应的应用:内容和Rightbar。
当单击父级中的链接时,我需要更新内容和右侧部分。
下面是部分代码:里面选择类
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRedirect to="/select" />
<Route path="/select" component={Select}>
<Route path="foo" component={Foo} />
<Route path="bar" component={Bar} />
<Route path="baz" component={Baz} />
</Route>
</Route>
</Router>
, destination);
:
<div className="sidebar">
<Link to="select/foo">Foo</Link>
<Link to="select/bar">Bar</Link>
<Link to="select/baz">Baz</Link>
</div>
<div className="content">
{this.props.children}
</div>
<div className="rightbar">
// I want to render a component here, but this.props.children can only contain one children
</div>
任何解决方案来解决这个问题,或者可能是一个更好的方式来做到这一点?
在此先感谢。
答
与之反应路由器可以使用多个组件,如
<Route path="/foo" components={{content: FooContent, rightbar: RightBarComponent}}/>