clj-commons / secretary

A client-side router for ClojureScript.
773 stars 64 forks source link

query param binding for Regex route #108

Open jngbng opened 4 years ago

jngbng commented 4 years ago

Following example in README does not work due to compilation failure.

(defroute #"/users/(\d+)" [id {:keys [query-params]}]
  (js/console.log (str "User: " id))
  (js/console.log (pr-str query-params)))

Compilation bug happens at the following line, which is actually dead code.

https://github.com/clj-commons/secretary/blob/1f2036a694e49f58a97c9401878602148f9d6310/src/secretary/core.clj#L23

I guess you already know this problem as you have used a workaround in the following test code:

https://github.com/clj-commons/secretary/blob/master/test/secretary/test/core.cljs#L162

Before the bug is resolved, the README would better be modified.

(defroute #"/users/(\d+)" [id q]
  (js/console.log (str "User: " id))
  (js/console.log (pr-str (:query-params q)))

;;; or

(defroute #"/users/(\d+)" {:as params}
  (let [[id {:keys [query-params]}] params]
    (js/console.log (str "User: " id))
    (js/console.log (pr-str query-params))))