除了可以在NavLink上设置“ activeClassName”和“ activeStyle”之外,在网站上创建指向非导航元素(例如,页眉或页脚中的非主导航)的其他路线的链接时,是否有任何理由在链接上使用NavLink不需要活动状态/类?
React Router v4 第1598篇《React Router v4 链接组件 It is used to create links which allow to navigate on different URLs
and When we click on any of that particular Link, it should load that page which is associated with that path without reloading the page.
Example: NavLink Component: If, we want to add some styles to the Link. So that when we click
on any particular link, it can be easily identified which Link is
active. For this react router provides NavLink instead of
Link. Now replace Link from Navlink and add properties activeStyle. The activeStyle properties mean when we click on the Link, it should be highlighted with different style so that we can
differentiate which link is currently active.
Example: 当需要在active上使用style或class属性时 让我们看一个例子: 链接 导航链接
<Link>
,可以使用<NavLink>
<Link to="/">Home</Link>
<NavLink to="/" activeClassName="active">Home</NavLink>
相似问题
问题类别
简而言之,当您使用时,所选元素上
<Link>
没有任何活动类。相反,
<NavLink>
选中的元素会突出显示,因为此元素被添加了一个活动类。希望对您有用。