From 96ab5d98d10268f90486a022479a85b15a29a81a Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Mon, 19 Sep 2022 21:45:22 +0630 Subject: [PATCH] Fix trailing slash breadcrumb bug --- src/components/Breadcrumbs.astro | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Breadcrumbs.astro b/src/components/Breadcrumbs.astro index f3f9fec..28cfe2e 100644 --- a/src/components/Breadcrumbs.astro +++ b/src/components/Breadcrumbs.astro @@ -1,5 +1,10 @@ --- -const breadcrumbList = Astro.url.pathname.split("/").slice(1); +// Remove current url path and remove trailing slash if exists +const currentUrlPath = Astro.url.pathname.replace(/\/+$/, ""); + +// Get url array from path +// eg: /tags/tailwindcss => ['tags', 'tailwindcss'] +const breadcrumbList = currentUrlPath.split("/").slice(1); // if breadcrumb is Home > Post > 'article-name' // replace 'article-name' to 'current post'