reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
oly 2020-12-17T10:31:46.423300Z

Hi I would like to know how I can handle an optional param like below

(reitit/router
   [["/editor" :editor]
    ["/editor/:slug" :editor]])

oly 2020-12-17T10:32:19.424Z

I guess I could have :editor and :editor-slug but is there a way to say slug does not have to exist

oly 2020-12-17T10:42:00.424500Z

this is using the frontend routing, but i imagine the syntax is the same for both

Steven Deobald 2020-12-17T16:08:31.425200Z

@oliver.marks I think your options are {:conflicts nil} for all routes or {:conflicting true} for a specific route.

oly 2020-12-17T16:28:52.425900Z

@steven427 thanks I thought would be a better way than that 😕

oly 2020-12-17T16:29:29.426500Z

although :editor :editor-slug did work and having them both call the same view function

oly 2020-12-17T16:30:11.427300Z

just felt like there should be a better way would explain why I could not find it in the docs as well

Steven Deobald 2020-12-17T17:37:41.431500Z

@oliver.marks Oh, sorry. I missed half your question. Yeah, I was actually just doing something similar (sort of the inverse of your problem with :editor) yesterday because I want to replicate Rails’ resource-oriented named-route lookups. I ended up hacking up an :alias feature for the path lookup: https://github.com/pariyatti/kosa/blob/e59bf595663381ab24f31fbbaf1e2f8337bf62a0/src/kosa_crux/routes.clj#L58 https://github.com/pariyatti/kosa/blob/e59bf595663381ab24f31fbbaf1e2f8337bf62a0/src/kosa_crux/views.clj#L15 That way I can do something like (path-for request :show id) and (path-for request :destroy id) and they both return the same path: "/images/:id"