Hi I would like to know how I can handle an optional param like below
(reitit/router
[["/editor" :editor]
["/editor/:slug" :editor]])
I guess I could have :editor and :editor-slug but is there a way to say slug does not have to exist
this is using the frontend routing, but i imagine the syntax is the same for both
@oliver.marks I think your options are {:conflicts nil}
for all routes or {:conflicting true}
for a specific route.
@steven427 thanks I thought would be a better way than that 😕
although :editor :editor-slug did work and having them both call the same view function
just felt like there should be a better way would explain why I could not find it in the docs as well
@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"