React Router V6 ISACTIVE不更新样式
升级到React Route Router V6后,有一个问题,即在活动活动时更新navlink
的样式。
代码看起来像这样:
{siteLinks.map({ href, name }) => {
return (
<NavLink
key={href}
to={href}
style={({ isActive }) => ({
backgroundColor: isActive ? 'gray' : 'transparent',
})}
>
<p>{name}</p>
</NavLink>
}
当我检查元素时,我会看到a
标签具有active> active
className,但style
未被选中向上。
如果我更改以下内容,它们都显示为灰色
<NavLink
key={href}
to={href}
style={{ backgroundColor: 'gray' }}
>
After upgrading to react router v6 there is an issue updating the style of a NavLink
when it is active.
The code looks like this:
{siteLinks.map({ href, name }) => {
return (
<NavLink
key={href}
to={href}
style={({ isActive }) => ({
backgroundColor: isActive ? 'gray' : 'transparent',
})}
>
<p>{name}</p>
</NavLink>
}
When I inspect the elements I see that the a
tag has the active
classname but the style
doesn't get picked up.
If I change to the following they all show as gray
<NavLink
key={href}
to={href}
style={{ backgroundColor: 'gray' }}
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用className
Give it a try with a className