books/src/components/NavLink.astro
2025-04-28 23:32:21 -04:00

15 lines
392 B
Plaintext

---
import type { HTMLAttributes } from 'astro/types';
type Props = HTMLAttributes<'a'>;
const { href, class: className, ...props } = Astro.props;
const { pathname } = Astro.url;
const isActive = href === pathname || href === pathname.replace(/\/$/, '');
---
<a class:list={[className, { 'underline underline-offset-2 decoration-1': isActive }]} href={href} {...props}>
<slot />
</a>