Refactor redirectToHome function to use URL object

This commit is contained in:
Cohee
2025-04-05 21:54:01 +03:00
parent 571356ffd9
commit e753e432be

View File

@@ -180,13 +180,18 @@ function displayError(message) {
* Preserves the query string.
*/
function redirectToHome() {
// After a login theres no need to preserve the
// noauto (if present)
const urlParams = new URLSearchParams(window.location.search);
// Create a URL object based on the current location
const currentUrl = new URL(window.location.href);
urlParams.delete('noauto');
// After a login there's no need to preserve the
// noauto parameter (if present)
currentUrl.searchParams.delete('noauto');
window.location.href = '/' + urlParams.toString();
// Set the pathname to root and keep the updated query string
currentUrl.pathname = '/';
// Redirect to the new URL
window.location.href = currentUrl.toString();
}
/**