fix: consider trailing slashes when calculating current path in blog example (#5272)

This commit is contained in:
Shoubhit Dash 2022-11-02 01:38:45 +05:30 committed by GitHub
parent b6afe2c1db
commit 0bab357c48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,9 @@
export interface Props extends astroHTML.JSX.AnchorHTMLAttributes {}
const { href, class: className, ...props } = Astro.props;
const isActive = href === Astro.url.pathname.replace(/\/$/, '');
const { pathname } = Astro.url;
const isActive = href === pathname || href === pathname.replace(/\/$/, '');
---
<a href={href} class:list={[className, { active: isActive }]} {...props}>