This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-27
Channels
- # announcements (24)
- # babashka (26)
- # beginners (8)
- # calva (8)
- # clojure (78)
- # clojure-europe (1)
- # clojure-norway (22)
- # clojurescript (14)
- # datascript (5)
- # datomic (8)
- # fulcro (22)
- # helix (9)
- # humbleui (11)
- # malli (4)
- # off-topic (28)
- # pedestal (5)
- # reitit (10)
- # shadow-cljs (2)
- # tools-build (8)
- # tools-deps (9)
Hello! I’m trying to get some query parameters going with reitit.frontend
and reitit.coercion.spec
. Here’s my route and app
:
(def routes [["/"
{:name :the/home-page
:view home-page
:query (s/keys :opt-un [::code])}]])
(defui app []
(rfe/start! (rf/router routes {:data {:coercion rss/coercion}})
(fn [m] (reset! match m))
{:use-fragment true})
(if @match
(let [view (-> @match :data :view)]
(pp/pprint @match)
(view @match))
[:pre (pp/pprint @match)]))
If I visit
, this is the value for @match
:
{:template "/",
:data
{:coercion #object[reitit.coercion.spec.t_reitit$coercion$spec17707],
:name :the/home-page,
:view #object[app$core$home_page],
:query #object[cljs.spec.alpha.t_cljs$spec$alpha19156]},
:result nil,
:path-params {},
:path "/",
:query-params {},
:fragment nil,
:parameters {:path {}, :query {}, :fragment nil}}
Getting my validation function as the value of :query
is unexpected, is that a correct expectation on my part?
Would really appreciate some pointers on what I’m doing wrong here.Don't you need to set up a controller for your route and add the query params there? https://github.com/metosin/reitit/blob/master/doc/frontend/controllers.md
Specifically, I think you need to call apply-controllers
I could be wrong though, it just seems to be what all my frontend reitit code does 😅
thanks for that! I don’t think so, unless I did it wrong. I tried this:
(s/def ::code string?)
(defn home-page [{{{:keys [code]} :query} :parameters :as params}]
(pp/pprint params)
(if (str/blank? code)
($ :a {:href access-token-uri} "Authenticate with YNAB")
($ :h1 (str "You are logged in! Your access code is " code))))
(def routes [["/"
{:name :the/home-page
:view home-page
:parameters {:query (s/keys :opt-un [::code])}
:controllers [{:parameters {:query [:code]}
:start (pp/pprint "starting home page")}]}]])
(defui app []
(rfe/start! (rf/router routes {:data {:coercion rss/coercion}})
(fn [new-match]
(swap! match
(fn [old-match]
(when new-match
(assoc new-match
:controllers (rfc/apply-controllers (:controllers old-match) new-match))))))
{:use-fragment true})
(if @match
(let [view (-> @match :data :view)]
(view @match))
[:pre (pp/pprint @match)]))
Hi! I don’t understand this paragraph (https://cljdoc.org/d/metosin/reitit/0.7.0-alpha7/doc/advanced/composing-routers). • Nested routers are not trivial and should be avoided. • For dynamic cases, nested routers is the only choice. • For other cases, nested routers are most likely a better option. Am I misunderstanding something here?
I believe that was it ☝️ nested routes is the way it’s normally done. A router is created from plain data. nested routers is when a router object refers to another router object.
unrelated, reitit does support interceptors now, right? I found this line in the docs: > • Pedestal supports interceptors (`reitit-http` module will support them too). https://github.com/metosin/reitit/blob/989ab72a58c1b220ffdae4810bb145ab52082d2c/doc/faq.md#L89. Git blame date is from 2018.