【发布时间】:2021-11-04 18:49:19
【问题描述】:
我想为当前页面设置一个活动类,但我遗漏了一些东西。
<Link href={`/projects/${project.id}`}>
<a
className={`${
router.pathname === `/projects/${projects.id}`
? "active"
: ""
}`}
>
{project.title}
</a>
</Link>
不确定这是否正确,因为当我控制台日志router.pathname 时,我得到/projects/[id]
这是正确的做法吗?还是有更好的方法?
【问题讨论】:
标签: reactjs react-router next.js nextjs-dynamic-routing