Skip to content

Commit 6e96f1d

Browse files
committed
fix: normalize pathname in MobileMenu too
1 parent a235553 commit 6e96f1d

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

src/components/MobileMenu.astro

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Props {
1515
const { navigationLinks, ctaLinks, pathname } = Astro.props;
1616
const lang = getLangFromUrl(Astro.url);
1717
const t = useTranslations(lang);
18+
const pathnameNormalized = pathname.replace(/\/$/, '') || '/';
1819
---
1920

2021
<div class="drawer drawer-start lg:hidden">
@@ -46,19 +47,23 @@ const t = useTranslations(lang);
4647
</div>
4748
<ul class="menu w-full gap-1 p-0">
4849
{
49-
navigationLinks.map((link) => (
50-
<li>
51-
<a
52-
class:list={[
53-
'btn btn-ghost btn-sm w-full justify-start',
54-
link.href === pathname && 'btn-outline btn-primary',
55-
]}
56-
href={link.href}
57-
>
58-
{link.label}
59-
</a>
60-
</li>
61-
))
50+
navigationLinks.map((link) => {
51+
const hrefStr = String(link.href);
52+
const isActive = hrefStr.replace(/\/$/, '') === pathnameNormalized;
53+
return (
54+
<li>
55+
<a
56+
class:list={[
57+
'btn btn-ghost btn-sm w-full justify-start',
58+
isActive && 'btn-outline btn-primary',
59+
]}
60+
href={link.href}
61+
>
62+
{link.label}
63+
</a>
64+
</li>
65+
);
66+
})
6267
}
6368
</ul>
6469
</div>

0 commit comments

Comments
 (0)