报错/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 />!!!

猜你喜欢

转载自www.cnblogs.com/liang-meng/p/11899815.html
今日推荐