简体   繁体   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>

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.

相关问题 为什么当已经有一个 key prop 时,这个警告会一直出现? 警告:列表中的每个孩子都应该有一个唯一的“key”道具 - 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 为什么当一个组件被包裹在高阶组件中时,新组件没有任何原始组件的 static 方法? - Why when a component is wrapped inside a High Order Component, the new component does not have any of the static methods of the original component? 为什么我收到警告! 当我使用 React Bootstrap Table 添加按钮时? - Why I'm getting Warning ! When i am adding button as a child <tr> using React Bootstrap Table? 为什么在导入组件时 typescript 会报错,但在同一文件中定义组件时不会报错? - Why does typescript complain when I import a component, but not when the component is defined in the same file? 为什么在我运行 create-react-app 时会出现此错误 - why does it give this error when I run create-react-app 我正在导出一个与 Redux 连接的组件,但它不起作用,我不知道为什么 - I am exporting a component connected with Redux but it does not work, I have no idea why 为什么我会收到一条警告,上面写着“列表中的每个孩子都应该有一个独特的关键道具”,但我已经为子组件提供了一个独特的关键道具 - Why do I get a warning that says “ each child in a list should have a unique key prop” but I already have a unique key prop for the child component 为什么当我按下可触摸的不透明度时,它会给出对象无效的错误作为反应孩子 - Why does it give a error of object are not valid as react child when I press touchable opacity 收到警告“警告:列表中的每个孩子都应该有一个唯一的”key“道具。” 当我的组件渲染时 - Getting warning “Warning: Each child in a list should have a unique ”key“ prop.” when my component render 为什么 jest-dom 在我使用它时会给出错误“TypeError:expect(...).not.toBeVisible is not a function” - Why does jest-dom give the error "TypeError: expect(...).not.toBeVisible is not a function" when I use it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM