[英]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>
I see this warning in my chrome console: 我在Chrome控制台中看到以下警告:
bundle.js:887 Warning: You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored
If I shouldn't add a component to the /user/:userId route, where am I suppose to add the component UserShow then? 如果我不应该将组件添加到/ user /:userId路由,那么我应该在哪里添加组件UserShow?
Nested routes should be added to the parent component directly: 嵌套路由应直接添加到父组件中:
const UserShow = props => (
<div>
<div>User info</div>
<Route path={`${props.match.url}/location/:locationId`} component={LocationShow} />
</div>
);
<Route path="/users/:userId" component={UserShow} />
LocationShow
will only be rendered when the path matches /users/:userId/location/:locationId
. 仅当路径匹配
/users/:userId/location/:locationId
时,才会渲染LocationShow
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.