Skip to content

Commit 5611c43

Browse files
committed
fix: href type handling in navbar active check
1 parent aa97c27 commit 5611c43

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/components/HeaderLink.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ type Props = HTMLAttributes<'a'>;
55
66
const { href, class: className, ...props } = Astro.props;
77
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '').replace(/\/$/, '') || '/';
8-
const hrefNormalized = href.replace(/\/$/, '') || '/';
8+
const hrefStr = typeof href === 'string' ? href : (href?.pathname ?? '/');
9+
const hrefNormalized = hrefStr.replace(/\/$/, '') || '/';
910
const subpath = pathname.match(/[^/]+/g);
1011
const isActive = hrefNormalized === pathname || hrefNormalized === `/${subpath?.[0] ?? ''}`;
1112
---

0 commit comments

Comments
 (0)