繁体   English   中英

当我有组件时,为什么添加子路由会发出此警告

[英]Why does adding a subroute give this warning when I have a component

  <Route path="/users/:userId" component={UserShow}>
    <Route path="/location/:locationId" component={LocationShow} />
  </Route>

我在Chrome控制台中看到以下警告:

 bundle.js:887 Warning: You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored 

如果我不应该将组件添加到/ user /:userId路由,那么我应该在哪里添加组件UserShow?

嵌套路由应直接添加到父组件中:

const UserShow = props => (
  <div>
    <div>User info</div>
    <Route path={`${props.match.url}/location/:locationId`} component={LocationShow} />
  </div>
);

<Route path="/users/:userId" component={UserShow} />

仅当路径匹配/users/:userId/location/:locationId时,才会渲染LocationShow

暂无
暂无

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

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