reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
gekkostate 2020-06-22T15:35:18.171100Z

Hi all, I have been reading the documentation on route conflicts and I was wondering if someone could shed some light on why the following routes are conflicting:

; -> /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
Apologies if this is very basic, I’m fairly new to this. How does the matching for routes work? Is there some documentation I can read on this? Thanks for your time!

2020-06-22T15:59:08.171500Z

@gekkostate Those three example routes can be ambiguous. If the reqeuested url is

/bulk/orders
do you want
:user-id = "bulk" on /:user-id/orders
or
:bulk-id = "orders" on /bulk/:bulk-id
? The route matching in reitit is not top-to-bottom or first match, depending on how the routing is configured: https://metosin.github.io/reitit/advanced/different_routers.html I use the :quarantine-router for most of my projects as I often have routes such as
/item/new
and
/item/:slug
together.

gekkostate 2020-06-22T16:10:36.172Z

Ahhhh, now I understand. Wonderful, thanks a bunch!

gekkostate 2020-06-22T16:10:52.172200Z

I think we’ll test out the quarantine router and see if it improves our situation.

ikitommi 2020-06-22T18:09:54.172400Z

putting :conflicts nil to router options selects automatically the quarantine router

naomarik 2020-06-22T20:02:17.172600Z

["/listing/:listing-id"
        {:view :listing}
        ["" {:name :listing}]
        ["/photos" {:conflicting true
                    :sub :photo
                    :name :listing-photos}]
        ["/{title}/photos" {:conflicting true
                            :sub :photo
                            :name :listing-with-title-and-photos}]
        ["/{title}" {:conflicting true
                     :name :listing-with-title}]]
@gekkostate Just had this problem and solved it like this.

naomarik 2020-06-22T20:03:35.172800Z

It selected the quarantine router automatically when I put the :conflicting true in the routes

gekkostate 2020-06-22T20:03:54.173Z

@ikitommi Oh that’s very interesting. We initially placed that and it indeed remove the warning however, it navigated to the wrong route! So, we decided to remove the conflicts nil and just resolve the conflict and this ended up working.

gekkostate 2020-06-22T20:04:40.173200Z

Sweeet, thanks for sharing @naomarik. I think we will try this approach in the future if there are conflicting routes that we have to deal with.

naomarik 2020-06-22T20:04:52.173400Z

yeah in my case this is passing all unit tests

naomarik 2020-06-22T20:05:01.173600Z

pretty damn flexible 🙂