Liking cljdoc? Tell your friends :D

Route Conflicts

We should fast if a router contains conflicting paths or route names.

When a Router is created via reitit.core/router, both path and route name conflicts are checked automatically. By default, in case of conflict, an ex-info is thrown with a descriptive message. In some (legacy api) cases, path conflicts should be allowed and one can override the path conflict resolution via :conflicts router option.

Path Conflicts

Routes with path conflicts:

(require '[reitit.core :as r])

(def routes
  [["/ping"]
   ["/:user-id/orders"]
   ["/bulk/:bulk-id"]
   ["/public/*path"]
   ["/:version/status"]])

Creating router with defaults:

(r/router routes)
; CompilerException clojure.lang.ExceptionInfo: Router contains conflicting route paths:
;
;    /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
;
;    /bulk/:bulk-id
; -> /:version/status
;
;    /public/*path
; -> /:version/status
;

To ignore the conflicts:

(r/router
  routes
  {:conflicts nil})
; => #object[reitit.core$linear_router$reify]

To just log the conflicts:

(r/router
  routes
  {:conflicts (fn [conflicts]
                (println (r/path-conflicts-str conflicts)))})
; Router contains conflicting route paths:
;
;    /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
;
; /bulk/:bulk-id
; -> /:version/status
;
; /public/*path
; -> /:version/status
;
; => #object[reitit.core$linear_router$reify]

Name conflicts

Routes with name conflicts:

(def routes
  [["/ping" ::ping]
   ["/admin" ::admin]
   ["/admin/ping" ::ping]])

Creating router with defaults:

(r/router routes)
;CompilerException clojure.lang.ExceptionInfo: Router contains conflicting route names:
;
;:reitit.core/ping
;-> /ping
;-> /admin/ping
;

There is no way to disable the name conflict resolution.

Can you improve this documentation? These fine people already did:
Tommi Reiman & tjalkane
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close