Fork me on GitHub
#reitit
<
2020-06-22
>
gekkostate15:06:18

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!

thegeez15:06:08

@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.

gekkostate16:06:36

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

gekkostate16:06:52

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

ikitommi18:06:54

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

naomarik20:06:17

["/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.

naomarik20:06:35

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

gekkostate20:06:54

@U055NJ5CC 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.

gekkostate20:06:40

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

naomarik20:06:52

yeah in my case this is passing all unit tests

naomarik20:06:01

pretty damn flexible 🙂