Skip to content

Commit

Permalink
Merge branch 'develop' into release/4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia authored May 19, 2022
2 parents de0a7c6 + 61b3e25 commit fe72b8f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions assets/js/instant-results/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,25 @@ const App = () => {
}

const state = JSON.stringify({ ...args, isOpen });
const params = getUrlParamsFromArgs(args, argsSchema, paramPrefix).toString();
const url = isOpen ? `?${params}` : window.location.origin + window.location.pathname;

if (history.state) {
history.pushState(state, document.title, url);
const params = getUrlParamsFromArgs(args, argsSchema, paramPrefix);
const url = new URL(window.location.href);
const keys = Array.from(url.searchParams.keys());

for (const key of keys) {
if (key.startsWith(paramPrefix)) {
url.searchParams.delete(key);
}
}

if (isOpen) {
params.forEach((value, key) => {
url.searchParams.set(key, value);
});
}

history.pushState(state, document.title, url.toString());
} else {
history.replaceState(state, document.title, window.location.href);
}
Expand Down

0 comments on commit fe72b8f

Please sign in to comment.