Fix empty query params map resulting in redundant '?' in path

This commit is contained in:
Valtteri Harmainen 2019-04-26 16:39:11 +03:00
parent 0919b46236
commit f7332d3bc4
3 changed files with 7 additions and 3 deletions

View file

@ -75,8 +75,8 @@
(rfe/href to path-params query-params) (rfe/href to path-params query-params)
(let [match (rf/match-by-path router to) (let [match (rf/match-by-path router to)
route (-> match :data :name) route (-> match :data :name)
params (not-empty (or path-params (:path-params match))) params (or path-params (:path-params match))
query (not-empty (or query-params (:query-params match)))] query (or query-params (:query-params match))]
(if match (if match
(rfe/href route params query) (rfe/href route params query)
to)))) to))))

View file

@ -67,7 +67,7 @@
([match] ([match]
(match->path match nil)) (match->path match nil))
([match query-params] ([match query-params]
(some-> match :path (cond-> query-params (str "?" (impl/query-string query-params)))))) (some-> match :path (cond-> (seq query-params) (str "?" (impl/query-string query-params))))))
;; ;;
;; Different routers ;; Different routers

View file

@ -354,6 +354,10 @@
(-> router (-> router
(r/match-by-name! ::route {:a "olipa", :b "kerran"}) (r/match-by-name! ::route {:a "olipa", :b "kerran"})
(r/match->path)))) (r/match->path))))
(is (= "/olipa/kerran"
(-> router
(r/match-by-name! ::route {:a "olipa", :b "kerran"})
(r/match->path {}))))
(is (= "/olipa/kerran?iso=p%C3%B6ril%C3%A4inen" (is (= "/olipa/kerran?iso=p%C3%B6ril%C3%A4inen"
(-> router (-> router
(r/match-by-name! ::route {:a "olipa", :b "kerran"}) (r/match-by-name! ::route {:a "olipa", :b "kerran"})