diff --git a/ignite-html-router.js b/ignite-html-router.js index 344e744..daf9492 100644 --- a/ignite-html-router.js +++ b/ignite-html-router.js @@ -472,6 +472,24 @@ class Router { return (params.has(name) ? params.get(name) : null); } } + + /** + * Removes a query parameter from the route search if it exists. + * @param {String} name + */ + static removeParameter(name) { + if (Router.hashMode) { + var params = new URLSearchParams(window.location.hash.includes("?") ? "?" + window.location.hash.split("?")[1] : ""); + if (params.has(name)) { + params.delete(name); + window.location.hash = window.location.hash.split("?")[0] + "?" + params.toString(); + } + } else { + var url = new URL(window.location); + url.searchParams.delete(name); + window.history.pushState(null, '', url.toString()); + } + } } Router.states = [];