Skip to content

Commit

Permalink
refactor: update changeLanguage function to use window.location.repla…
Browse files Browse the repository at this point in the history
…ce for navigation
  • Loading branch information
omdxp committed Dec 31, 2024
1 parent 091015b commit f4ba386
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions web/src/redux/actions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { captureException } from "@sentry/react";
import { Language, Languages } from "src/components/locale/languages";

export const changeLanguage = (languageCode: Language["code"]) => {
// case 1: url has no language code, eg: /about / or root
// case 2: url has language code, eg: /en/about /ar/ or /ar
// case 3: url has language code, but not in the list of supported languages, eg: /es/about /es/ or /es

let newPath = window.location.pathname;
const language = Languages.find(({ code }) => code === languageCode);
if (!language) {
Expand All @@ -28,5 +24,5 @@ export const changeLanguage = (languageCode: Language["code"]) => {
newPath = newPath.replace(new RegExp(`^/${language.code}`), "");
}

window.location.assign(newPath);
window.location.replace(newPath);
};

0 comments on commit f4ba386

Please sign in to comment.