欢迎光临散文网 会员登陆 & 注册

react路由报错

2021-12-03 10:37 作者:老尚带你学前端  | 我要投稿

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

解决方法:

在index.js文件中,用<Routes>包围 <Route>

修改:

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

为,

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

就这样式的,

import {Route, Routes, HashRouter} from 'react-router-dom'

<Routes>

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

</Routes>


react路由报错的评论 (共 条)

分享到微博请遵守国家法律