P粉4329300812023-08-11 13:33:58
You cannot use this in functional components that are only accessible within class components. To achieve the effect you want, you only need to write the code manually, for example:
<Link href="/store" className={`${pathname === "/store" ? "active":""}`} >商店</Link>
Also be careful not to use && in className, because if the condition is not true, it will add false to your className, so you can use the ternary operator to add "" when the condition is false .