Merge pull request #782 from ae-utbm/ajax-navigation-history

Ajax navigation history in uv guide
This commit is contained in:
thomas girod
2024-08-26 22:29:19 +02:00
committed by GitHub
4 changed files with 110 additions and 53 deletions

View File

@ -74,6 +74,7 @@ const initialUrlParams = new URLSearchParams(window.location.search);
* @enum {number}
*/
const History = {
NONE: 0,
PUSH: 1,
REPLACE: 2,
};
@ -82,9 +83,12 @@ const History = {
* @param {string} key
* @param {string | string[] | null} value
* @param {History} action
* @param {URL | null} url
*/
function update_query_string(key, value, action = History.REPLACE) {
const url = new URL(window.location.href);
function update_query_string(key, value, action = History.REPLACE, url = null) {
if (!url){
url = new URL(window.location.href);
}
if (!value) {
// If the value is null, undefined or empty => delete it
url.searchParams.delete(key)
@ -96,8 +100,10 @@ function update_query_string(key, value, action = History.REPLACE) {
}
if (action === History.PUSH) {
history.pushState(null, document.title, url.toString());
history.pushState(null, "", url.toString());
} else if (action === History.REPLACE) {
history.replaceState(null, document.title, url.toString());
history.replaceState(null, "", url.toString());
}
return url;
}