Browse Source

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
momchil-anachkov 6 years ago
parent
commit
e4f0e80dfb
2 changed files with 4 additions and 4 deletions
  1. 2 2
      assets/js/academic-search.js
  2. 2 2
      assets/js/academic.js

+ 2 - 2
assets/js/academic-search.js

@@ -43,8 +43,8 @@ function getSearchQuery(name) {
 
 
 // Set query in URI without reloading the page.
 // Set query in URI without reloading the page.
 function updateURL(url) {
 function updateURL(url) {
-  if (history.pushState) {
-    window.history.pushState({path:url}, '', url);
+  if (history.replaceState) {
+    window.history.replaceState({path:url}, '', url);
   }
   }
 }
 }
 
 

+ 2 - 2
assets/js/academic.js

@@ -50,9 +50,9 @@
   }
   }
 
 
   function removeQueryParamsFromUrl() {
   function removeQueryParamsFromUrl() {
-    if (window.history.pushState) {
+    if (window.history.replaceState) {
       let urlWithoutSearchParams = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash;
       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);
     }
     }
   }
   }