reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Jon Johnson 2021-02-14T20:18:26.100600Z

Hi everyone. I’m building a website using reagent + re-frame, and using reitit for routing. I’m having a little trouble understanding how to match query parameters passed through a URL into a path. I have a couple of routes setup as such:

(def routes
  ["/"
   [""
    {:name      :routes/home
     :view      views/home
     :controllers
     [{:start (fn [& params] (js/console.log "Entering home page"))
       :stop  (fn [& params] (js/console.log "Leaving home page"))}]}]
   ["?search=:term"
    {:name      :routes/search
     :view      views/results-panel
     :parameters {:query {:search {:term string?}}}
     :link-text "Search"
     :controllers
     [{:parameters {:query {:search :term}}
       :start (fn [] (re-frame/dispatch [::events/get-results :term]))}]}])
When I try passing a string matching the :routes/search path, it matches against the :routes/home path instead
(r/match-by-path routes "/?search=hello")
 => #reitit.core.Match{:template "/", :data {...}, :result nil, :path-params {}, :path "/", :query-params {:search "hello"}, :parameters {:path {}, :query {:search "hello"}}}
I feel like there’s something pretty simple here that I’m missing, though I’m not quite sure