books/src/components/NavLink.astro

15 lines
392 B
Text
Raw Normal View History

2025-04-28 23:32:21 -04:00
---
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>