Skip to content

Instantly share code, notes, and snippets.

export const getUrlParameterValue = (name) => {
const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results !== null ? results[1] || 0 : null;
};
export const updateParameterInUrl = (name, value) => {
const { protocol, host, pathname, search } = window.location;
const paramReg = new RegExp(name + '=[a-z]+');
const newSearch = search.replace(paramReg, name + '=' + value);
const newUrl = protocol + "//" + host + pathname + newSearch;