简体   繁体   English

反应路由器未提供适当的组件

[英]React router not render appropriate component

I have such structure of routes 我有这样的路线结构

<Router history={hashHistory}>
    <Route name="Dashboard" path="/" component={App}>   
        <Route name='Not found' path="*" component={NotFound}/>
    </Route>
</Router>

When i work on /admin/product page, child component not working. 当我在/ admin / product页面上工作时,子组件无法工作。 I wrote "bicycle" in my opinion. 我认为我写了“自行车”。 In render function i wrote such code: 在渲染函数中,我编写了这样的代码:

render() {
   return (
       { this.props.children ? this.props.children : <My component /> }
   );
}

I am stuck on /admin/product/:id/edit. 我被困在/ admin / product /:id / edit上。 When i update my form, component fully rerender and i cant use componentWillReceiveProps , componentWillUpdate . 当我更新表单时,组件将完全重新呈现,并且我无法使用componentWillReceivePropscomponentWillUpdate I tried to debbug, but my code doesn't go in this methods. 我试图调试,但是我的代码没有进入这种方法。

Question is how i can work in child components and use componentWillReceiveProps , componentWillUpdate functions 问题是我如何在子组件中工作并使用componentWillReceivePropscomponentWillUpdate函数

You should check the docs. 您应该检查文档。 https://github.com/ReactTraining/react-router/blob/master/docs/guides/RouteConfiguration.md https://github.com/ReactTraining/react-router/blob/master/docs/guides/RouteConfiguration.md

There is such an example like this: 有这样的例子:

render((
  <Router>
    <Route path="/" component={App}>
      <Route path="about" component={About} />
      <Route path="inbox" component={Inbox}>
        <Route path="messages/:id" component={Message} />
      </Route>
    </Route>
  </Router>
), document.body)

URL: /inbox/messages/:id 网址: /inbox/messages/:id

Components: App -> Inbox -> Message 组件: App -> Inbox -> Message

So, in your case, child component's url is /admin/offers/admin/offer/:id/edit . 因此,在您的情况下,子组件的网址为/admin/offers/admin/offer/:id/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM