Liking cljdoc? Tell your friends :D

Route Conflicts

Most routing libraries allow conflicting paths within a router. On lookup, the first match is used making rest of the matching routes effecively unreachable. This is not good, especially if route tree is merged from multiple sources.

Reitit resolves this by running explicit conflicit resolution when a Router is created. Conflicting routes are passed into a :conflicts callback. Default implementation throws ex-info with a descriptive message.

Examples router with conflicting routes:

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

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

By default, ExceptionInfo is thrown:

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

Just logging the conflicts:

(r/router
  routes
  {:conflicts (comp println reitit/conflicts-str)})
; Router contains conflicting routes:
;
;    /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
;
;    /bulk/:bulk-id
; -> /:version/status
;
;    /public/*path
; -> /:version/status
;

Can you improve this documentation?Edit on GitHub

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

× close