Preserves the current URL as the return URL when language is changed

This commit is contained in:
BinaryAlley committed 2024-12-26 20:12:51 +02:00
1 parent f43a8fd098
commit 8cbfb56389
3 files changed
+32 -22

No files matched your search

@@ -393,6 +393,7 @@ async function updateContentAsync(url, addToHistory) {
const state = { url, content, title };
history.pushState(state, title, url);
}
updateLanguageUrls();
}
} catch (error) {
notificationService.show(jsLocalizedMessages.navigationFailed, NotificationType.ERROR);
@@ -400,6 +401,15 @@ async function updateContentAsync(url, addToHistory) {
}
}
// Update language switcher links with the current URL
function updateLanguageUrls() {
document.querySelectorAll('a.lang-set').forEach(link => {
const url = new URL(link.href);
url.searchParams.set('returnUrl', window.location.pathname + window.location.search);
link.href = url.toString();
});
}
//+======================================================================================+
//| Common Helper Functions |
//+======================================================================================+