Skip to content

Commit aa97c27

Browse files
committed
fix: pathname parsing
1 parent 545bdb1 commit aa97c27

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/components/HeaderLink.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import type { HTMLAttributes } from 'astro/types';
44
type Props = HTMLAttributes<'a'>;
55
66
const { href, class: className, ...props } = Astro.props;
7-
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '');
7+
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '').replace(/\/$/, '') || '/';
8+
const hrefNormalized = href.replace(/\/$/, '') || '/';
89
const subpath = pathname.match(/[^/]+/g);
9-
const isActive = href === pathname || href === `/${subpath?.[0] ?? ''}`;
10+
const isActive = hrefNormalized === pathname || hrefNormalized === `/${subpath?.[0] ?? ''}`;
1011
---
1112

1213
<a

0 commit comments

Comments
 (0)