Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 当我有一个组件时,为什么添加子例程会给出这个警告_Reactjs_React Router - Fatal编程技术网

Reactjs 当我有一个组件时,为什么添加子例程会给出这个警告

Reactjs 当我有一个组件时,为什么添加子例程会给出这个警告,reactjs,react-router,Reactjs,React Router,我在chrome控制台中看到以下警告: 如果我不应该将组件添加到/user/:userId路由,那么我应该在哪里添加组件UserShow?嵌套路由应该直接添加到父组件: bundle.js:887 Warning: You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored LocationShow仅

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


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

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

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

LocationShow仅在路径匹配/users/:userId/location/:locationId时才会呈现。

是否尝试在路径匹配时同时显示UserShow和LocationShow?该路由表达式正确吗?如果我将其硬编码为URL,它可以工作,例如path=/users/9/location/:locationId,但您的却不能。不确定那个反勾号和$在做什么。它是一个模板文字,使字符串更漂亮:你能试着记录props.match吗?如果您使用的是类,请执行此.props.match。在您的示例中,props.match.url应该是/users/9。我删除了path=中的问题,并执行了此操作。path?这是什么路?
bundle.js:887 Warning: You should not use <Route component> and <Route
children> in the same route; <Route children> will be ignored
const UserShow = props => (
  <div>
    <div>User info</div>
    <Route path={`${props.match.url}/location/:locationId`} component={LocationShow} />
  </div>
);

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