This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-12
Channels
- # announcements (5)
- # babashka (1)
- # beginners (193)
- # calva (79)
- # cider (18)
- # clara (4)
- # clojure (38)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-nl (12)
- # clojure-sweden (1)
- # clojure-uk (50)
- # clojurescript (37)
- # conjure (30)
- # cursive (3)
- # data-science (2)
- # datalog (7)
- # datomic (12)
- # events (2)
- # expound (3)
- # figwheel-main (1)
- # fulcro (45)
- # graalvm (1)
- # jobs (1)
- # jobs-discuss (11)
- # luminus (1)
- # malli (5)
- # off-topic (32)
- # reagent (6)
- # reitit (32)
- # shadow-cljs (25)
- # spacemacs (2)
- # sql (22)
- # vim (6)
I'm looking for an example of using reitit on the frontend and backend, where the frontend is an SPA and does not use hash fragments but normal urls. I can't quite figure out how to have the backend serve the frontend on any un-matched route, while still reserving certain routes for the backend (like /api)
Hey hey! I asked a similar question a little while back and this is what I came up with: https://gist.github.com/athomasoriginal/14c6cfa1500bc1ab1a90a98b9d7217a0 - let me know if this helps!!
I have nginx sitting in front that redirects 404s to index.html. I guess you could achieve the same with a default handler that always returns index.html. If you’re using reitit-ring, you can provide the default-handler when creating the router.
The general idea is that you have a main set of routes, if anything is not matched by those, you can use the default handler and add in another route check.
This is another good place to go to checkout other examples: https://github.com/metosin/reitit/tree/master/examples
On the frontend side however, how do you initialize when landing on a nested (non-root /) route? I'm using re-frame. The backend is serving the SPA properly now on any path, but on the frontend itself reitit isn't matching the path when I enter the page at a non root path (that is, / works client side but /something/deeper doesn't)
Do you have a simple example of your routing setup + entry point to your app?
Example: this is another simple example of handling front end routing: https://gist.github.com/athomasoriginal/eadc022482c3432943c400cc8eeb1788
Yeah, the above example should also work with HistoryAPI
(def router
(reitit/router
[""
["/" {:name :home :view #'home-ui}]
["/something-else" {:name :home :view #'another-ui}]]
{:compile coercion/compile-request-coercers}))
(defn navigate! [match _]
(rf/dispatch [:common/navigate match]))
(defn start-router! []
(rfe/start!
router
navigate!
{:use-fragment false}))
(start-router!)
What’s navigate!
doing?
Yeah, so I just want to see what navigate!
is doing. For example, in the gist I provided, mine just updates the match
atom. The general idea is i’m trying to isolate where something is going wrong. A quick way to do that is to see if the problem is in your routing logic (reitit) (in my example, routes
) or is the problem in the app entry point (in my example current-page
)
so browsing to /
loads the :home
route, but navigating to /something-else
loads a blank page as the match is nil.
Should I be seeding it with the initial window location or does reitit frontend pick that up?
It should pickup on it. The idea is: • page loads • the url is read + passed to reitit • reitit matches • the match is passed to Reagent I’m not an expert with reitit yet, but can you try updating your routing structure to
[["/" {:name :home :view #'home-ui}]
["/something-else" {:name :home :view #'another-ui}]]
Also, why add the #'
(var quote) in front of your :views
?I'd like to extend reitit.http.coercion/coerce-request-interceptor
to also check additional :env
data I attach during the processing of a request (think of dynamic per-request things like db and cache connections, etc). Ideally, I'd just re-use the existing reitit-malli plumbing for coercion, but that's only checking for specific keys: https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/coercion.cljc#L37-L42
This doesn't seem like a far-fetched feature requests - perhaps someone has already done this? Not sure if I should just write a new interceptor, extend the existing malli-coercion interceptor with new ParameterCoercion keys, or perhaps just hack and piggyback on an existing params key.
Hi, is there something like compojure's wrap-routes
in reitit? https://weavejester.github.io/compojure/compojure.core.html#var-wrap-routes
@pithyless multipart-interceptor does a similar thing: https://github.com/metosin/reitit/blob/master/modules/reitit-interceptors/src/reitit/http/interceptors/multipart.clj#L39&L60
@ilyab you can do ~same by mounting middleware to specific routes or methods, so no.