2017-06-13 156 views
0

enter image description here陣營父將數據發送到多個孩子

我有具有上述結構,其中父具有側邊欄和呈現兩個孩子一個反應的應用:內容和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> 

任何解決方案來解決這個問題,或者可能是一個更好的方式來做到這一點?

在此先感謝。

回答

0

與之反應路由器可以使用多個組件,如

<Route path="/foo" components={{content: FooContent, rightbar: RightBarComponent}}/> 

讀爲Multi Named Components