1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Reacte路由报错:A <Route> is only ever to be used as the child of <Routes> element never rendered direct

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

时间:2022-07-15 10:48:51

相关推荐

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>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。