mirror of
https://github.com/metosin/reitit.git
synced 2026-01-01 06:08:25 +00:00
Store uncoerced query-params in frontend match
This matches path-params and fragment.
This commit is contained in:
parent
c11d21d9ec
commit
0bd1b94274
2 changed files with 7 additions and 2 deletions
|
|
@ -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)))))
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
{:template "/"
|
||||
:data {:name ::frontpage}
|
||||
:path-params {}
|
||||
:query-params {}
|
||||
:path "/"
|
||||
:parameters {:query {}
|
||||
:path {}}})
|
||||
|
|
@ -32,6 +33,7 @@
|
|||
{:template "/foo"
|
||||
:data {:name ::foo}
|
||||
:path-params {}
|
||||
:query-params {}
|
||||
:path "/foo"
|
||||
:parameters {:query {}
|
||||
:path {}}})
|
||||
|
|
@ -59,6 +61,7 @@
|
|||
(is (= (r/map->Match
|
||||
{:template "/:id"
|
||||
:path-params {:id "5"}
|
||||
:query-params {}
|
||||
:path "/5"
|
||||
:parameters {:query {}
|
||||
:path {:id 5}}})
|
||||
|
|
@ -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}}})
|
||||
|
|
@ -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}}})
|
||||
|
|
|
|||
Loading…
Reference in a new issue