[英]NavLink component in React-Router-DOM not accepting style prop with function
[英]_ref is undefiend when using react-router-dom's Navlink component
在设置一个新的 React web 应用程序项目时,在安装react-router-dom
v^6.8.0 之后,我使用从react-router-dom
导入的NavLink
的那一刻是这样的:
<NavLink>
<MyCustomJsx />
</NavLink>
该应用程序会崩溃说:
Unexpected Application Error! _ref is undefined
检查控制台后:
React Router caught the following error during render TypeError: _ref is undefined
,并且在另一个不同的第二个日志中: The above error occurred in the <Link> component: Stacktrace here
谷歌搜索没有任何结果,因为关于 react 的 ref 的帖子和问题太多了, HTML ref 是未定义的,但不是关于这个 underscore-ref: _ref
。 删除<NavLink>
摆脱了错误......有什么想法吗?
在闲逛了一会儿之后,我不小心向NavLink
提供了to
prop,其字符串值如下:
<NavLink to="/downloads">
<MyCustomJsx />
</NavLink>
然后错误消失,应用程序启动。 所以我猜当你不提供to
道具时_ref
是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.