From 51bb26ae348aac156d8f17e2da563eddcd3acc20 Mon Sep 17 00:00:00 2001 From: Ludy Date: Sun, 17 Mar 2024 10:57:17 +0100 Subject: [PATCH] Fix: Error after logging out and selecting another language (#924) Fix exception url after logout --- src/main/resources/static/js/languageSelection.js | 4 +++- src/main/resources/templates/login.html | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/resources/static/js/languageSelection.js b/src/main/resources/static/js/languageSelection.js index 413bebe0..ee9ab03b 100644 --- a/src/main/resources/static/js/languageSelection.js +++ b/src/main/resources/static/js/languageSelection.js @@ -47,8 +47,10 @@ function handleDropdownItemClick(event) { localStorage.setItem("languageCode", languageCode); const currentUrl = window.location.href; - if (currentUrl.indexOf("?lang=") === -1) { + if (currentUrl.indexOf("?lang=") === -1 && currentUrl.indexOf("&lang=") === -1) { window.location.href = currentUrl + "?lang=" + languageCode; + } else if (currentUrl.indexOf("&lang=") !== -1 && currentUrl.indexOf("?lang=") === -1) { + window.location.href = currentUrl.replace(/&lang=\w{2,}/, "&lang=" + languageCode); } else { window.location.href = currentUrl.replace(/\?lang=\w{2,}/, "?lang=" + languageCode); } diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 1a900fd9..19a4b728 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -118,10 +118,12 @@ console.log("currentLang", currentLang) console.log("languageCode", languageCode) const currentUrl = window.location.href; - if (currentUrl.indexOf('?lang=') === -1) { - window.location.href = currentUrl + '?lang=' + languageCode; + if (currentUrl.indexOf("?lang=") === -1 && currentUrl.indexOf("&lang=") === -1) { + window.location.href = currentUrl + "?lang=" + languageCode; + } else if (currentUrl.indexOf("&lang=") !== -1 && currentUrl.indexOf("?lang=") === -1) { + window.location.href = currentUrl.replace(/&lang=\w{2,}/, "&lang=" + languageCode); } else { - window.location.href = currentUrl.replace(/\?lang=\w{2,}/, '?lang=' + languageCode); + window.location.href = currentUrl.replace(/\?lang=\w{2,}/, "?lang=" + languageCode); } } dropdown.innerHTML = event.currentTarget.innerHTML; // Update the dropdown button's content