Skip to content

Commit

Permalink
Store uncoerced query-params in frontend match
Browse files Browse the repository at this point in the history
This matches path-params and fragment.
  • Loading branch information
Deraen committed Aug 23, 2018
1 parent c11d21d commit 0bd1b94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/reitit-frontend/src/reitit/frontend.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
(let [uri (.parse Uri path)]
(if-let [match (reitit/match-by-path router (.getPath uri))]
(let [q (query-params uri)
match (assoc match :query-params q)
;; Return uncoerced values if coercion is not enabled - so
;; that tha parameters are always accessible from same property.
parameters (or (coercion/coerce! (assoc match :query-params q))
parameters (or (coercion/coerce! match)
{:path (:path-params match)
:query q})]
(assoc match :parameters parameters)))))
Expand Down
6 changes: 5 additions & 1 deletion test/cljs/reitit/frontend/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{:template "/"
:data {:name ::frontpage}
:path-params {}
:query-params {}
:path "/"
:parameters {:query {}
:path {}}})
Expand All @@ -32,6 +33,7 @@
{:template "/foo"
:data {:name ::foo}
:path-params {}
:query-params {}
:path "/foo"
:parameters {:query {}
:path {}}})
Expand Down Expand Up @@ -59,6 +61,7 @@
(is (= (r/map->Match
{:template "/:id"
:path-params {:id "5"}
:query-params {}
:path "/5"
:parameters {:query {}
:path {:id 5}}})
Expand All @@ -71,7 +74,7 @@
(is (= (r/map->Match
{:template "/:id"
:path-params {:id "5"}
;; Note: query not included in path
:query-params {:mode "foo"}
:path "/5"
:parameters {:path {:id 5}
:query {:mode :foo}}})
Expand All @@ -84,6 +87,7 @@
(is (= (r/map->Match
{:template "/:id"
:path-params {:id "5"}
:query-params {:mode "foo"}
:path "/5"
:parameters {:path {:id 5}
:query {:mode :foo}}})
Expand Down

0 comments on commit 0bd1b94

Please sign in to comment.