I'm quite new to deno and the Fresh framework (which is really hard to google for answers). I wanna make a nav link a different background color of it matches the pathname
this is what I tried:
const NavLink = ({ href, children }: NavLinkProps) => {
const isActive = location.pathname === href
const bgClass = isActive ? tw`bg-gray-900` : tw`bg-transparent`
return (
<a
href={href}
className={tw`px-3 py-2 rounded-md text-sm font-medium text-white ${bgClass}`}
>
{children}
</a>
)
}
But location
is undefined..
You can get current URL data from
PageProps.url
and pass it to your component.From the docs