Skip to content

Commit

Permalink
chore: support isActive link all subpages (withastro#9694)
Browse files Browse the repository at this point in the history
* chore: support isActive link all subpages

* Update examples/blog/src/components/HeaderLink.astro

Co-authored-by: Florian Lefebvre <[email protected]>

---------

Co-authored-by: Nate Moore <[email protected]>
Co-authored-by: Florian Lefebvre <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent bcc504d commit 2adf3b5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/blog/src/components/HeaderLink.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down

0 comments on commit 2adf3b5

Please sign in to comment.