Skip to content

Commit 7662a3f

Browse files
committed
instantsearch.js: Fix history navigation
1 parent f273257 commit 7662a3f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/js/instantsearch.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
doc.getElementById('searchbox').addEventListener('keyup', function (event) {
2424
const url = new URL(window.location);
25-
url.searchParams.set('sq', event.target.value);
26-
url.searchParams.set('p', 1);
27-
window.history.pushState({}, '', url);
25+
url.searchParams.set('sq', event.target.value.trim());
26+
if (url.href != window.location.href) {
27+
url.searchParams.set('p', 1);
28+
window.history.pushState({}, '', url);
29+
}
2830
})
2931

3032
doc.getElementById('pagination').addEventListener('click', function (event) {
@@ -34,6 +36,10 @@
3436
window.history.pushState({}, '', url);
3537
})
3638

39+
window.onpopstate = (event) => {
40+
window.location.reload();
41+
};
42+
3743
search.addWidgets([
3844
instantsearch.widgets.configure({
3945
hitsPerPage: 10,

0 commit comments

Comments
 (0)