Reacte路由报错:A <Route> is only ever to be used as the child of <Routes> element, never rendered direct

由于react-router-dom更新到6版本以后,有一些写法开始与5不同
1.包裹方式不同

A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.

代码:jsx 5版本不需要外面有一层Routes

<div className="panel-body">
    {/* 注册路由 */}
    <Routes> 
      <Route path='/about' element={<About/>}/>
   	  <Route path='/home' element={<Home/>}/>
    </Routes> 
</div>

2.注册路由方式不一样
5版本注册路由

<Routes>
  	<Route path='/about' component={About}/>
   	<Route path='/home' component={Home}/> 
</Routes>

6版本注册路由

<Routes>
  	<Route path='/about' element={<About/>}/>
   	<Route path='/home' element={<Home/>}/>
</Routes>


版权声明:本文为weixin_45866961原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。