Unverified Commit 4cad3635 authored by Florent Chehab's avatar Florent Chehab
Browse files

feat(front): helpers for urls manipulation

parent cfb11ddd
* Get the get param value in the url
* @param key {string}
export function getGetParamInUrl(key) {
const getParamsInUrl = new URL(document.location).searchParams;
return getParamsInUrl.get(key);
* @param key {string} Key of the get parameter
* @param value {string} Value of the get parameter
* @param mode {"replace"|"push"|"reload"} replace: silent update of the history | push: add entry to history | reload: replace and hard reload the page
export function setGetParamInUrl(key, value, mode = "replace") {
const getParamsInUrl = new URL(document.location).searchParams;
getParamsInUrl.set(key, value);
if (mode === "replace") {
window.history.replaceState(null, null, `?${getParamsInUrl.toString()}`);
} else if (mode === "push") {
window.history.pushState(null, null, `?${getParamsInUrl.toString()}`);
} else if (mode === "reload") {
setGetParamInUrl(key, value, "replace");
} else {
// eslint-disable-next-line no-console
console.error(`Unsupported mode '${mode}', doing nothing`);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment