Skip to content

Commit 59bd4f1

Browse files
committed
fix: compare pathnames, not full URLs
1 parent 389c146 commit 59bd4f1

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/components/Header.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { getLangFromUrl, useTranslations } from '@/i18n/utils';
77
const lang = getLangFromUrl(Astro.url);
88
const t = useTranslations(lang);
99
const pathname = Astro.url.pathname.replace(/\/$/, '') || '/';
10-
console.log('[DEBUG Header] pathname:', pathname);
1110
1211
const navigationLinks = [
1312
{ href: getRelativeLocaleUrl(lang, '/'), label: t('nav.home') },
@@ -53,8 +52,8 @@ const ctaLinks = {
5352
{
5453
navigationLinks.map((link) => {
5554
const hrefStr = String(link.href);
56-
const isActive = hrefStr.replace(/\/$/, '') === pathname;
57-
console.log('[DEBUG Header] hrefStr:', hrefStr, 'isActive:', isActive);
55+
const linkPathname = new URL(hrefStr).pathname.replace(/\/$/, '') || '/';
56+
const isActive = linkPathname === pathname;
5857
return (
5958
<li>
6059
<a

src/components/MobileMenu.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ const pathnameNormalized = pathname.replace(/\/$/, '') || '/';
4646
<Logo size="nav" showTitle />
4747
</div>
4848
<ul class="menu w-full gap-1 p-0">
49-
{
49+
{
5050
navigationLinks.map((link) => {
5151
const hrefStr = String(link.href);
52-
const isActive = hrefStr.replace(/\/$/, '') === pathnameNormalized;
52+
const linkPathname = new URL(hrefStr).pathname.replace(/\/$/, '') || '/';
53+
const isActive = linkPathname === pathnameNormalized;
5354
return (
5455
<li>
5556
<a

0 commit comments

Comments
 (0)