![](/img/trans.png)
[英]Why does this warning keep appearing when there is already a key prop? Warning: Each child in a list should have a unique “key” prop
[英]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.