浏览代码

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 年之前
父节点
当前提交
e4f0e80dfb
共有 2 个文件被更改,包括 4 次插入4 次删除
  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.
 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() {
-    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);
     }
   }