Fork me on GitHub

Hi everyone! Quick question about query parameters in reitit router. I'm using reitit.core/router as my router. I would like to access parameters in my path for example: /bar?great=foo. Currently, I have my router setup like the following

(def router
   [["/" :home]
    ["/search" :search]]))
What is the way to access query parameters?


@gekkostate the core router is unaware of query parameters. If you are routing in the browser, you should check reitit.frontend/router which also parses query-params. Or reitit.ring/router for the same for backend


Ohhhh ok! Cool, I'll check that out. I've been fiddling with the luminus template which contains reagent + re-frame and reitit (frontend is the core router and backend is ring/router). They have an interesting setup with the core router but I'm going to shift to the reitit.frontend/router because that seems to be the best way forward. Thanks a bunch for your help!


@gekkostate here is an example

(def router (reitit.frontend/router ["/" ["search"]]))

(reitit.frontend/match-by-path router "/search?q=foo")
=> #reitit.core.Match{:template "/search", :data {}, :result nil, :path-params {}, :path "/search", :query-params {:q "foo"}, :parameters {:path {}, :query {:q "foo"}}}


Thanks a bunch, the example really helped! Quick question. Is there a standard way to pass those params onto the view? I'm following this: My attempt was to subscribe to ::current-route which passes the entire match to the view. However, that means that routes which have nothing to do with subscribed view are also passed and that doesn't look like the good approach.

(defn sub-page2
  (let [params @(re-frame/subscribe [::current-route])]
    (println params)
     [:h1 "This is sub-page 2"]]))