This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-30
Channels
- # announcements (40)
- # babashka (41)
- # beginners (32)
- # calva (15)
- # clara (8)
- # clj-kondo (14)
- # cljs-dev (30)
- # clojure (37)
- # clojure-dev (8)
- # clojure-europe (21)
- # clojure-norway (21)
- # clojure-uk (4)
- # clojured (3)
- # clojurescript (4)
- # community-development (10)
- # core-async (13)
- # cursive (23)
- # datomic (15)
- # emacs (9)
- # fulcro (3)
- # google-cloud (4)
- # graphql (24)
- # gratitude (2)
- # holy-lambda (4)
- # honeysql (5)
- # hyperfiddle (9)
- # keechma (1)
- # klipse (5)
- # lsp (23)
- # malli (4)
- # missionary (32)
- # pathom (28)
- # re-frame (2)
- # reagent (40)
- # reitit (17)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (25)
- # specter (3)
- # vim (19)
- # xtdb (41)
Is it possible to achieve the following magic?
(def routes
[["/" {some magic to actually refer to /book1}
]
["/book1" {:name :route/page1
:view #'page-fn}]
])
semantically speaking you might want to return permanent redirect here - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
Don’t wanna happen on the user side but instead I wanna grouping the “/” and “/book1" together. Feeling like reitit should be able to do it.
then you can simply extract handler for "/book1" into a var and use it in two places
Doesn’t really want to go to that approach. For example, does reitit support
(def routes
[["/" (fn [router] (find-by-name :route/page1))]
["/book1" {:name :route/page1
:view #'page-fn}]])
Where the find-by-name
function returns the {:name :route/page1 :view #’page-fn}sounds like reverse routing - https://cljdoc.org/d/metosin/reitit/0.5.18/doc/ring/reverse-routing
btw, the function associated with the route should be a request handler not some preprocessor for routes
You should be able to do this:
["" {:view #'page-fn}
["/"]
["/book1" {:name :route/page1}]]
E.g. move common stuff up.Looking at the code, the coerce
function might do it ? https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/impl.cljc/#L74
Maybe you can elaborate what you actually want. Do you use reitit server-side or client-side? Is all you want that the same handler is resolved using two different paths?
> I wanna grouping the “/” and “/book1" together.
This is what you can do with nesting and a ""
prefix 🤷
>
["" {:view #'page-fn}
> ["/"]
> ["/book1" {:name :route/page1}]]
>
Yes. This does the job. But I also have a /orange1 which have a different handler. So moving #’page-fn up is a little bit weird.To avoid an X-Y problem, I am writing an SPA (so frontend side) with reitit. I want the effect that when user hits http://foo.com/. it is the same as hitting http://foo.com/#book1
You can group however you want:
[["" {:view #'page-fn}
["/"]
["/book1"]]
["/orange1" {:view #'orange-fn}]]