Browse Source

enhance: use query params in fragments for graph switching

Andelf 2 years ago
parent
commit
e929a191ec
2 changed files with 13 additions and 10 deletions
  1. 1 1
      src/main/frontend/handler/ui.cljs
  2. 12 9
      src/main/frontend/util.cljc

+ 1 - 1
src/main/frontend/handler/ui.cljs

@@ -300,4 +300,4 @@
     (when target-repo
       (if (util/electron?)
        (ipc/ipc "openNewWindow" target-repo)
-       (js/window.open (str config/app-website "?graph=" target-repo) "_blank")))))
+       (js/window.open (str config/app-website "#/?graph=" target-repo) "_blank")))))

+ 12 - 9
src/main/frontend/util.cljc

@@ -1552,15 +1552,18 @@ Arg *stop: atom, reset to true to stop the loop"
            (string/ends-with? s "]]")))))
 #?(:cljs
    (defn parse-params
-     "Parse URL parameters into a hashmap"
+     "Parse URL parameters in hash(fragment) into a hashmap"
      []
      (if node-test?
        {}
-       (->> js/window
-           (.-location)
-           (.-search)
-           (new js/URLSearchParams)
-           (seq)
-           (js->clj)
-           (into {})
-           (walk/keywordize-keys)))))
+       (when-let [fragment (-> js/window
+                               (.-location)
+                               (.-hash)
+                               not-empty)]
+         (when (string/starts-with? fragment "#/?")
+           (->> (subs fragment 2)
+                (new js/URLSearchParams)
+                (seq)
+                (js->clj)
+                (into {})
+                (walk/keywordize-keys)))))))