This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-12
Channels
- # babashka (37)
- # beginners (27)
- # biff (1)
- # calva (18)
- # cider (45)
- # clj-on-windows (5)
- # cljsrn (1)
- # clojure (90)
- # clojure-art (3)
- # clojure-uk (1)
- # clojurescript (7)
- # core-logic (4)
- # datomic (4)
- # events (2)
- # fulcro (3)
- # hyperfiddle (23)
- # leiningen (66)
- # malli (1)
- # meander (7)
- # nrepl (1)
- # off-topic (9)
- # pathom (1)
- # re-frame (15)
- # reitit (19)
- # remote-jobs (1)
- # shadow-cljs (103)
Quick question. What is the canonical way to access route data within a handler?
by default inject-match?
is true so the data will be in the injected Match
which the handler can access
If you compile, you can access that data at compile time, too, so you can close over relevant data before returning an interceptor
So the right key to look at in the context is :reitit.core/match
Is that correct?
And on compiled routes, there’s no real need to specify a handler right? The compilation yields a handler effectively?
Interesting. Why does the compiler fire twice in this example?
(defn handler [req]
{:status 200
:body "pong"})
(def routes ["/ping" {:name ::ping
:get {:handler handler}
:interceptors [{:name ::interceptor
:compile (fn [ctx _]
(println "compiler " ctx)
{:enter identity
:leave identity})}]}])
(http/router routes)
I mean, I made this up, but why does the compile trigger twice?
The second time it is called it seems to also add the :no-doc?
key in the ctx
ring/get-match
?
Also, what does compilation mean for an interceptor based approach?
I’ve figured most of it out, thanks to @ben.sless
One question remains. Why is the compile function invoked multiple times when http/routes
is called?
I’ve looked at the code and I am still not sure why the compile function is invoked twice. I’ve no problems with it, but just trying to understand the process. http/router
invokes a middleware/compile-routes
whats the recommended way to changing a route in reitit-frontend pragmatically I am using push-state but I am noticing that does not trigger the routers navigate function so does not reload the page correctly where as a clicked rfe/href does.
Found out this was due to hot reloading not working correctly, so not related to reitit push-state calls -on-navigate manually when called.