fix: only checking last part of filter on destination pages to create basePathWithoutFilters

Approved-by: Hrishikesh Vaipurkar
This commit is contained in:
Erik Tiekstra
2025-07-17 13:07:37 +00:00
parent f2716c8b5e
commit 876a9cab7f

View File

@@ -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
}