diff --git a/modules/reitit-frontend/src/reitit/frontend.cljs b/modules/reitit-frontend/src/reitit/frontend.cljs index 8145404a..071e296d 100644 --- a/modules/reitit-frontend/src/reitit/frontend.cljs +++ b/modules/reitit-frontend/src/reitit/frontend.cljs @@ -3,7 +3,14 @@ [reitit.coercion :as coercion] [reitit.coercion :as rc] [reitit.core :as r]) - (:import goog.Uri)) + (:import goog.Uri + goog.Uri.QueryData)) + +(defn- query-param [^goog.Uri.QueryData q k] + (let [vs (.getValues q k)] + (if (< (alength vs) 2) + (aget vs 0) + (vec vs)))) (defn query-params "Given goog.Uri, read query parameters into Clojure map." @@ -11,7 +18,7 @@ (let [q (.getQueryData uri)] (->> q (.getKeys) - (map (juxt keyword #(.get q %))) + (map (juxt keyword #(query-param q %))) (into {})))) (defn match-by-path diff --git a/test/cljs/reitit/frontend/core_test.cljs b/test/cljs/reitit/frontend/core_test.cljs index 20009088..22ac1db2 100644 --- a/test/cljs/reitit/frontend/core_test.cljs +++ b/test/cljs/reitit/frontend/core_test.cljs @@ -39,6 +39,16 @@ :path {}}}) (rf/match-by-path router "/foo"))) + (is (= (r/map->Match + {:template "/foo" + :data {:name ::foo} + :path-params {} + :query-params {:mode ["foo", "bar"]} + :path "/foo" + :parameters {:query {:mode ["foo", "bar"]} + :path {}}}) + (rf/match-by-path router "/foo?mode=foo&mode=bar"))) + (is (= "/foo" (r/match->path (rf/match-by-name router ::foo))))