summaryrefslogtreecommitdiff
path: root/examples/blog/src/components
diff options
context:
space:
mode:
authorGravatar だいき <13312135+daikiejp@users.noreply.github.com> 2024-01-30 06:50:26 -0500
committerGravatar GitHub <noreply@github.com> 2024-01-30 11:50:26 +0000
commit2adf3b56eb74df2d39d0c4dfdc753c9b9911dd4d (patch)
tree69cbeb458469608c0e73667f4025c661a71466a7 /examples/blog/src/components
parentbcc504dae03f9ceed1aa502b76cfa2c6d2fbbfc8 (diff)
downloadastro-2adf3b56eb74df2d39d0c4dfdc753c9b9911dd4d.tar.gz
astro-2adf3b56eb74df2d39d0c4dfdc753c9b9911dd4d.tar.zst
astro-2adf3b56eb74df2d39d0c4dfdc753c9b9911dd4d.zip
chore: support isActive link all subpages (#9694)
* chore: support isActive link all subpages * Update examples/blog/src/components/HeaderLink.astro Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Diffstat (limited to 'examples/blog/src/components')
-rw-r--r--examples/blog/src/components/HeaderLink.astro3
1 files changed, 2 insertions, 1 deletions
diff --git a/examples/blog/src/components/HeaderLink.astro b/examples/blog/src/components/HeaderLink.astro
index 3dd439be1..bb600fb65 100644
--- a/examples/blog/src/components/HeaderLink.astro
+++ b/examples/blog/src/components/HeaderLink.astro
@@ -6,7 +6,8 @@ type Props = HTMLAttributes<'a'>;
const { href, class: className, ...props } = Astro.props;
const { pathname } = Astro.url;
-const isActive = href === pathname || href === pathname.replace(/\/$/, '');
+const subpath = pathname.match(/[^\/]+/g);
+const isActive = href === pathname || href === '/' + subpath?.[0];
---
<a href={href} class:list={[className, { active: isActive }]} {...props}>