Fork me on GitHub
#reitit
<
2021-01-06
>
Oz15:01:51

I'm doing my first steps with reitit and get errors about route conflicts, the documentation talks about various features regarding route conflicts, but I couldn't find an explanation on what is a route conflict. What is the conflict between :

["/public/*path"]
and
["/:version/status"]
They seem completely different. From searching google, looks like this term is not that commonly used.

Steven Deobald15:01:41

@ozfraier /:version will also match /public since reitit just sees a string matching :version. As long as you have /public first, it will match first and everything will work as you expect (where "/v3/status" or whatever won't match /public and match the parameterized route further down the line. You can use {:conflicting true} to get past this, as per: https://cljdoc.org/d/metosin/reitit/0.5.10/doc/basics/route-conflicts ...which I found by googling "reitit route conflict". 😉

Steven Deobald15:01:29

@ozfraier Two thoughts: (1) The reitit docs look intimidating at first, but they're actually just surprisingly comprehensive. Reitit is a rather small and polite library but in my experience it has always done exactly what I've wanted it to do... once I read the docs and understand what I'm looking for. (2) You probably don't want to parameterize the inner portions of your routes, if you can help it. I'd suggest "/status/:version" in the example you gave.

Oz15:01:23

Thank you @steven427, I actually took the example from the same page you linked, I admit, I wasn't super sharp thinking why the routes in the example are conflicting, the docs treat this as a given, and it is very logical after you explained it. maybe just a small hint like : "routes conflict when the same path, e.g "public/status" can match different routes:" can be helpful. My real world conflict turns out to be: "/projects/:project" and "/projects/new" and reitit is smart to point it out.

Steven Deobald15:01:09

Yup, I have quite a few of that exact conflict (`"/:id" vs. "/new"`) which led me to asking the same questions a couple months ago. 🙂 At one point, @ikitommi mentioned this to me:

the conflict resolver could be smarter and know that
[["/kikka/kikka"]
 ["/kikka/:id"]]
actually is not conflicting as the fixed term(s) comes first. PR welcome :)
...Clojure isn't my day job, so I haven't attempted that patch. @ozfraier If you're ever in the mood, you could give it a shot. 🙂

Oz16:01:33

Thanks, that's a nice idea, I think I will go with "project/:project" where :project is a name that does not exist yet, defaults to a new project form.