From 69b3112d3243abbf7d5f504d0d14ef878bbeea4e Mon Sep 17 00:00:00 2001
From: itsMapleLeaf <19603573+itsMapleLeaf@users.noreply.github.com>
Date: Sun, 12 Mar 2023 16:50:11 -0500
Subject: [PATCH] account for trailing slashes
---
packages/website/src/components/nav-link.astro | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/packages/website/src/components/nav-link.astro b/packages/website/src/components/nav-link.astro
index 8a28620..06e6212 100644
--- a/packages/website/src/components/nav-link.astro
+++ b/packages/website/src/components/nav-link.astro
@@ -2,13 +2,16 @@
export type Props = astroHTML.JSX.AnchorHTMLAttributes & {
href: string
}
-const url = Astro.url
-const linkUrl = new URL(Astro.props.href, url)
+
+const removeTrailingSlash = (str: string) => str.replace(/\/$/, "")
+
+const linkUrl = new URL(Astro.props.href, Astro.url)
+
+const isActive =
+ removeTrailingSlash(Astro.url.pathname) ===
+ removeTrailingSlash(linkUrl.pathname)
---
-
+