File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ interface Props {
1515const { navigationLinks, ctaLinks, pathname } = Astro .props ;
1616const lang = getLangFromUrl (Astro .url );
1717const 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 >
You can’t perform that action at this time.
0 commit comments