diff --git a/.changeset/forty-trees-type.md b/.changeset/forty-trees-type.md new file mode 100644 index 0000000000..b759676b25 --- /dev/null +++ b/.changeset/forty-trees-type.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-makeswift": patch +--- + +Fix 404 error on switching between localized Makeswift pages with locale-specific paths when TRAILING_SLASH=true diff --git a/core/vibes/soul/primitives/navigation/_actions/localized-pathname.ts b/core/vibes/soul/primitives/navigation/_actions/localized-pathname.ts index 0d74d3c1fe..4911fdf43e 100644 --- a/core/vibes/soul/primitives/navigation/_actions/localized-pathname.ts +++ b/core/vibes/soul/primitives/navigation/_actions/localized-pathname.ts @@ -25,8 +25,11 @@ const getPageInfo = async ({ const getPathname = (variants: Array<{ locale: string; path: string }>, locale: string) => variants.find((v) => v.locale === locale)?.path; +const stripTrailingSlash = (pathname: string) => + pathname !== '/' ? pathname.replace(/\/+$/, '') : pathname; + export async function getLocalizedPathname({ - pathname, + pathname: inputPathname, activeLocale, targetLocale, }: { @@ -34,6 +37,9 @@ export async function getLocalizedPathname({ activeLocale: string | undefined; targetLocale: string; }) { + // Makeswift page pathnames are always stored without a trailing slash + const pathname = stripTrailingSlash(inputPathname); + // fallback to page info for default locale if there is no page info for active locale const fallbackPageInfo = activeLocale === defaultLocale