Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-trees-type.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ 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,
}: {
pathname: string;
activeLocale: string | undefined;
targetLocale: string;
}) {
// Makeswift page pathnames are always stored without a trailing slash
const pathname = stripTrailingSlash(inputPathname);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalize the pathname before looking it up.


// fallback to page info for default locale if there is no page info for active locale
const fallbackPageInfo =
activeLocale === defaultLocale
Expand Down
Loading