useHref() may be used only in the context of a <Router> component

"react-router-dom": "^6.3.0".使用Link组件时提示报错,useHref()只能在Router组件中使用。

 

 

解决办法:在index.tsx文件使用Router组件包裹App组件,同时删除router.js路由注册文件中的Router包裹组件,使得所有组件处在同一个Router组件之下

<React.StrictMode>
  <HashRouter>
    <App />
  </HashRouter>
</React.StrictMode>

  

posted @ 2022-07-08 17:59  风生`  阅读(547)  评论(0编辑  收藏  举报