React Router v4 &lt;NavLink&gt;vs <链接>好处 [英] React Router v4 &lt;NavLink&gt; vs &lt;Link&gt; benefits

查看:39
本文介绍了React Router v4 &lt;NavLink&gt;vs <链接>好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了在 NavLink 上设置activeClassName"和activeStyle"的能力之外,在创建到其他路由的链接时,是否有任何理由使用 NavLink 而不是 Link-您网站上不需要活动状态/类的导航元素(即不是页眉或页脚中的主要导航)?

Besides the ability to set an "activeClassName" and "activeStyle" on NavLink, is there any reason to use NavLink over Link when creating links to other routes on non-navigational elements (ie. not main nav in header or footer) on your site that don't need an active state/class?

推荐答案

官方文档 很清楚:

<Link> 的特殊版本,当它匹配当前 URL 时,它将向呈现的元素添加样式属性.

A special version of the <Link> that will add styling attributes to the rendered element when it matches the current URL.

因此,答案是.除上述原因外,没有其他原因.

Thus, the answer is NO. There are no other reasons except the mentioned one.

这篇关于React Router v4 &lt;NavLink&gt;vs <链接>好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆