@ou-imdt/utils
Version:
Utility library for interactive media development
10 lines • 468 B
JavaScript
/**
* Sets URL parameters
* @returns {Object} An object containing the URL parameters to be set as key-value pairs.
*/
export default function setUrlParams(params, newEntry = false) {
const urlParams = new URLSearchParams(location.search);
const action = (newEntry === true) ? 'push' : 'replace';
Object.entries(params).forEach(([key, value]) => urlParams.set(key, value));
history[`${action}State`](null, '', `?${urlParams.toString()}${location.hash}`);
}