React-router:如何将`components` prop传递给祖先?

时间:2017-03-07 16:36:53

标签: reactjs react-router

目前,我的结构类似于

<Route path="/" component={App}>
  <Route path="page1" components={{content: C1, aside: A1}} />
  <Route path="page2" components={{content: C2, aside: A2}} />

  <Route path="page3" components={{content: C3, aside: A3}} >
    <Route path="page3-sub" components={{content: C3Sub, aside: A3Sub}} />
  </Route>

</Route>

使用此路由配置page3-sub的组件不会转到App:它们被覆盖&#34;&#34;由page3提供。有没有办法让这个路由结构使用page3-sub的组件?

1 个答案:

答案 0 :(得分:0)

我无法测试这个,但我相信你只需要解开它们:

<Route path="/" component={App}>
  <Route path="page1" components={{content: C1, aside: A1}} />
  <Route path="page2" components={{content: C2, aside: A2}} />
  <Route path="page3" components={{content: C3, aside: A3}} />
  <Route path="page3-sub" components={{content: C3Sub, aside: A3Sub}}/>
</Route>