I’m currently attempting to implement a global navbar in Next that detects the current page to highlight that link. Below is the current implementation:
<Link href="/about" className={`${window.location.href.contains('/about') ? 'text-red-500 cursor-default' : 'link-underline'} mx-2`}>About</Link>
Unfortunately, this throws a “window is not defined” ReferenceError. I’m assuming Next is rendering this server-side so window
can’t be accessed, how can I read the current URL inline like this? (Or, am I going about this the wrong way)
1