File tree Expand file tree Collapse file tree
modules/reitit-frontend/src/reitit/frontend
test/cljs/reitit/frontend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 289289 New query params can be given as a map, or a function taking
290290 the old params and returning the new modified params.
291291
292- Note: The query parameter values aren't coereced, so the
293- update fn will see string values for all query params ."
292+ The current path is matched against the routing tree, and the match data
293+ (schema, coercion) is used to encode the query parameters ."
294294 ([history new-query-or-update-fn]
295295 (set-query history new-query-or-update-fn nil ))
296296 ([history new-query-or-update-fn {:keys [replace] :as opts}]
297297 (let [current-path (-get-path history)
298- new-path (rf/set-query-params current-path new-query-or-update-fn)]
298+ ; ; FIXME: What if there is no match?
299+ match (rf/match-by-path (.-router history) current-path)
300+ query-params (if (fn? new-query-or-update-fn)
301+ (new-query-or-update-fn (:query (:parameters match)))
302+ new-query-or-update-fn)
303+ new-path (rf/match->path match query-params (:fragment (:parameters match)))]
299304 (if replace
300305 (.replaceState js/window.history nil " " (-href history new-path))
301306 (.pushState js/window.history nil " " (-href history new-path)))
Original file line number Diff line number Diff line change 6969 ; ; 2. /bar/2?a=1
7070 6 (do (is (= " /bar/2?a=1" url)
7171 " update-query with map" )
72- (rfe/set-query #(assoc % :b " foo " ) {:replace true }))
72+ (rfe/set-query #(assoc % :q " x " ) {:replace true }))
7373 ; ; 0. /
7474 ; ; 1. /bar/2
7575 ; ; 2. /bar/2?a=1&b=foo
76- 7 (do (is (= " /bar/2?a=1&b=foo " url)
76+ 7 (do (is (= " /bar/2?a=1&q=__x " url)
7777 " update-query with fn" )
7878 (.go js/window.history -2 ))
7979 ; ; 0. /
You can’t perform that action at this time.
0 commit comments