Fork me on GitHub
#reitit
<
2022-06-30
>
pinkfrog11:06:43

Is it possible to achieve the following magic?

(def routes
  [["/"     {some magic to actually refer to /book1} 
            ]
   ["/book1" {:name :route/page1
              :view #'page-fn}]
   
   ])

delaguardo12:06:34

semantically speaking you might want to return permanent redirect here - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

pinkfrog12:06:55

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.

delaguardo12:06:02

then you can simply extract handler for "/book1" into a var and use it in two places

pinkfrog12:06:40

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}

delaguardo12:06:40

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 🤷

pinkfrog13:06:26

>

["" {: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.

pinkfrog13:06:18

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

Ferdinand Beyer13:06:36

You can group however you want:

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

pinkfrog13:06:07

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

pinkfrog13:06:11

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 ?

pinkfrog00:07:29

I end up embedding an express server inside electron