与this.props.children混淆反应路由器v1.0.0

时间:2015-11-16 03:23:07

标签: reactjs react-router

我有这样的路由器:

<Route path="/" component={App}>
  <IndexRoute component={Dashboard} />
  <Route path="info" component={Info}>
    <Route path="c/:cid" component={CompanyDetail} />
    <Route path="p/:pid" component={ProjectDetail} />
  </Route>
</Route>

我的信息组件是由react-redux连接的高阶组件。

作为react-router v1.0.0中的更改,如果达到this.props.children,Info组件中的/info/c/123应代表CompanyDetail组件。但是当我尝试到达/info时,我得到了这个:

enter image description here

我似乎Info组件中this.props.children的价值本身?如果我尝试访问/info/c/123,也遇到此问题,Info组件包含Info组件本身,其中包含CompanyDetail组件。

enter image description here

这让我感到困惑,任何想法?

2 个答案:

答案 0 :(得分:0)

我认为你应该将CompanyDetail和ProjectDetail路由定义为Info route的子路由。

例如:

<Route path="info" component={Info}>
    <Route path="info/c/:cid" component={CompanyDetail} />
    <Route path="info/p/:pid" component={ProjectDetail} />
</Route>

答案 1 :(得分:0)

我自己修好了。我在我的App组件中找到了包含代码的旧代码:

React.cloneElement(this.props.children, {...this.props})

通过防止将this.props.children复制给儿童来解决。

相关问题