Fork me on GitHub

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 -


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}


btw, the function associated with the route should be a request handler not some preprocessor for routes

Ferdinand Beyer12:06:16

You should be able to do this:

["" {:view #'page-fn}
 ["/book1" {:name :route/page1}]]
E.g. move common stuff up.

Ferdinand Beyer12:06:05

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?

Ferdinand Beyer12:06:03

> 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 it is the same as hitting

Ferdinand Beyer13:06:36

You can group however you want:

[["" {:view #'page-fn}
 ["/orange1" {:view #'orange-fn}]]


yes. I think this one is the way to go.


I am developing with electron, so the window.location.href is file:///Users/pinkfrog/example/resources/app/index.html, so reitit does not where to begin the match. How can I tell reitit to treat as if it is visiting something like ?


I end up embedding an express server inside electron