From e4f0e80dfb3440a9a784ecd43b7fd2d09a42273d Mon Sep 17 00:00:00 2001 From: momchil-anachkov Date: Mon, 1 Jul 2019 13:27:05 +0300 Subject: [PATCH] fix: browser back button after searching does not behave properly Switch URL updating strategy from pushState to replaceState in order to avoid pushing all search queries to the browser history Fix #1166 --- assets/js/academic-search.js | 4 ++-- assets/js/academic.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/academic-search.js b/assets/js/academic-search.js index d4a84ae1..4b262c3e 100644 --- a/assets/js/academic-search.js +++ b/assets/js/academic-search.js @@ -43,8 +43,8 @@ function getSearchQuery(name) { // Set query in URI without reloading the page. function updateURL(url) { - if (history.pushState) { - window.history.pushState({path:url}, '', url); + if (history.replaceState) { + window.history.replaceState({path:url}, '', url); } } diff --git a/assets/js/academic.js b/assets/js/academic.js index 992adc6a..f144a830 100644 --- a/assets/js/academic.js +++ b/assets/js/academic.js @@ -50,9 +50,9 @@ } function removeQueryParamsFromUrl() { - if (window.history.pushState) { + if (window.history.replaceState) { let urlWithoutSearchParams = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash; - window.history.pushState({path:urlWithoutSearchParams}, '', urlWithoutSearchParams); + window.history.replaceState({path:urlWithoutSearchParams}, '', urlWithoutSearchParams); } }