Skip to content

Commit

Permalink
fix: updates replacement logic for locale
Browse files Browse the repository at this point in the history
- replaces "&locale=de" and "locale=de" to avoid trailing "&"
  • Loading branch information
mohitb35 committed Mar 27, 2023
1 parent bc40a59 commit 0ac60ef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export async function middleware(
}

const localeParam = req.nextUrl.searchParams.get("locale");
const queryString = req.nextUrl.search.replace(`locale=${localeParam}`, "");
const localeTestRegex = new RegExp("&?locale=" + localeParam); //looks for locale as a query param (optionally preceded by &)
const queryString = req.nextUrl.search.replace(localeTestRegex, "");

// locale is removed from query parameters and user is redirected if the locale is supported
if (localeParam) {
Expand Down

0 comments on commit 0ac60ef

Please sign in to comment.