报错/Warning: You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored

这个报错在以下情形会出现

第一种

<Switch>
       <Route exact path="/home/index" component={HomeIndex} />
       <Route path="/home/order" component={HomeOrder}>
          <Route path="/home/order2" component={HomeOrder2}></Route>
       </Route>
       <Route path="/home/assets" component={Assets} />
    </Switch>    

Route组件下面不能嵌套Route组件,react-router4版本以上就不让这么写了

第二种(超级坑!!!)

<Switch>
       <Route exact path="/home/index" component={HomeIndex} />
       <Route path="/home/order" component={HomeOrder}>
       </Route>
       <Route path="/home/assets" component={Assets} />
    </Switch> 

Route组件之间不能有空格换行!所以,要么<Route></Route>这种样子或者写成一个自闭和标签<Route />!!!

posted @ 2019-11-20 18:56  LiangM  阅读(2049)  评论(0编辑  收藏  举报