From 876a9cab7faf72fcaa677f44156c017d1a5b2f45 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Thu, 17 Jul 2025 13:07:37 +0000 Subject: [PATCH] fix: only checking last part of filter on destination pages to create basePathWithoutFilters Approved-by: Hrishikesh Vaipurkar --- .../stores/destination-data/helper.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/scandic-web/stores/destination-data/helper.ts b/apps/scandic-web/stores/destination-data/helper.ts index 30340cc20..d0c3b73f6 100644 --- a/apps/scandic-web/stores/destination-data/helper.ts +++ b/apps/scandic-web/stores/destination-data/helper.ts @@ -71,9 +71,16 @@ export function getBasePathNameWithoutFilters( pathname: string, filterSlugs: string[] ) { - const pathSegments = pathname.split("/") - const filteredSegments = pathSegments.filter( - (segment) => !filterSlugs.includes(segment) - ) - return filteredSegments.join("/") + if (!filterSlugs.length) { + return pathname + } + + const lastSlashIndex = pathname.lastIndexOf("/") + const lastSegment = pathname.slice(lastSlashIndex + 1) + + if (filterSlugs.includes(lastSegment)) { + return pathname.slice(0, lastSlashIndex) || "/" + } + + return pathname }