Skip to content

Instantly share code, notes, and snippets.

@cahva
Created December 3, 2024 09:54
Show Gist options
  • Save cahva/8f70777ceff47515b909e01168d28e43 to your computer and use it in GitHub Desktop.
Save cahva/8f70777ceff47515b909e01168d28e43 to your computer and use it in GitHub Desktop.
Set language parameter if it does not exist
// Only proceed if we're not on a register page
if (!window.location.pathname.includes('/register')) {
const params = new URLSearchParams(window.location.search);
// Only add language param if it doesn't exist
if (!params.has('language')) {
params.append('language', 'en');
// Construct new URL with updated params
const newUrl = window.location.pathname + '?' + params.toString() + window.location.hash;
window.history.replaceState(null, '', newUrl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment