2017-12-10 14:57:09 +00:00
# Route Conflicts
2017-09-18 05:30:03 +00:00
2019-04-02 19:44:24 +00:00
We should fail fast if a router contains conflicting paths or route names.
2017-09-18 05:30:03 +00:00
2019-01-27 20:11:47 +00:00
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.
2017-09-18 05:30:03 +00:00
2018-07-21 05:49:20 +00:00
## Path Conflicts
Routes with path conflicts:
2017-09-18 05:30:03 +00:00
```clj
2017-10-30 06:46:20 +00:00
(require '[reitit.core :as r])
2017-09-18 05:30:03 +00:00
(def routes
[["/ping"]
["/:user-id/orders"]
["/bulk/:bulk-id"]
["/public/*path"]
["/:version/status"]])
```
2018-07-21 05:49:20 +00:00
Creating router with defaults:
2017-09-18 05:30:03 +00:00
```clj
2017-10-30 06:46:20 +00:00
(r/router routes)
2018-07-21 05:49:20 +00:00
; CompilerException clojure.lang.ExceptionInfo: Router contains conflicting route paths:
2017-09-18 05:30:03 +00:00
;
; /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
;
; /bulk/:bulk-id
; -> /:version/status
;
; /public/*path
; -> /:version/status
;
```
2018-07-21 05:49:20 +00:00
To ignore the conflicts:
```clj
(r/router
routes
{:conflicts nil})
; => #object [reitit.core$linear_router$reify]
```
To just log the conflicts:
2017-09-18 05:30:03 +00:00
```clj
2017-10-30 06:46:20 +00:00
(r/router
2017-09-18 05:30:03 +00:00
routes
2018-07-21 05:49:20 +00:00
{:conflicts (fn [conflicts]
(println (r/path-conflicts-str conflicts)))})
; Router contains conflicting route paths:
2017-09-18 05:30:03 +00:00
;
; /:user-id/orders
; -> /public/*path
; -> /bulk/:bulk-id
;
2018-07-21 05:49:20 +00:00
; /bulk/:bulk-id
2017-09-18 05:30:03 +00:00
; -> /:version/status
;
2018-07-21 05:49:20 +00:00
; /public/*path
2017-09-18 05:30:03 +00:00
; -> /:version/status
;
2018-07-21 05:49:20 +00:00
; => #object [reitit.core$linear_router$reify]
2017-09-18 05:30:03 +00:00
```
2018-07-21 05:49:20 +00:00
## Name conflicts
Routes with name conflicts:
```clj
(def routes
[["/ping" ::ping]
["/admin" ::admin]
["/admin/ping" ::ping]])
```
Creating router with defaults:
```clj
(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.