Fork me on GitHub

Quick question. What is the canonical way to access route data within a handler?

Ben Sless10:03:38

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?

Ben Sless10:03:52

Should be, yes


And on compiled routes, there’s no real need to specify a handler right? The compilation yields a handler effectively?

Ben Sless10:03:29

No, the handler is part of the data and is required, afaict


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

Ben Sless10:03:19

This gets a bit too far into the implementation details than I know


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

Oliver Marks19:03:11

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.

Oliver Marks14:03:43

Found out this was due to hot reloading not working correctly, so not related to reitit push-state calls -on-navigate manually when called.