首页 > 解决方案 > react-router-bootstrap LinkContainer 组件失败并出现 TypeError (0 , _reactRouterDom.withRouter) is not a function

问题描述


我一直在使用 react-router-bootstrap 反应库中的 LinkContainer 一段时间,但目前在我导入它时它会抛出此错误:

TypeError (0 , _reactRouterDom.withRouter) 不是函数

我在这个代码框中有我非常简单的反应应用程序在这里

请帮我调试一下。

标签: javascriptreactjsroutesreact-routerreact-router-bootstrap

解决方案


你必须选择,要么降级你的 react-router-dom 版本(到 v5.3.0),所以方法 withRouter 将再次可用(由 react-router-bootstrap 使用)或者你关闭 react-router-bootstrap 并使用 useNavigate钩:

const navigate = useNavigate();
...
<Nav.Link onClick={() => navigate('configuration')}>

推荐阅读