![](/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.