mirror of
https://github.com/metosin/reitit.git
synced 2026-02-17 16:25:57 +00:00
Log warnings about missing route or params
This commit is contained in:
parent
358fbc19c6
commit
ae109e5350
3 changed files with 29 additions and 3 deletions
|
|
@ -17,7 +17,10 @@
|
||||||
(defn about-page []
|
(defn about-page []
|
||||||
[:div
|
[:div
|
||||||
[:h2 "About frontend"]
|
[:h2 "About frontend"]
|
||||||
[:a {:href "http://google.com"} "external link"]])
|
[:ul
|
||||||
|
[:li [:a {:href "http://google.com"} "external link"]]
|
||||||
|
[:li [:a {:href (rfh/href @router ::foobar)} "Missing route"]]
|
||||||
|
[:li [:a {:href (rfh/href @router ::item)} "Missing route params"]]]])
|
||||||
|
|
||||||
(defn item-page [match]
|
(defn item-page [match]
|
||||||
(let [{:keys [path query]} (:parameters match)
|
(let [{:keys [path query]} (:parameters match)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
""
|
""
|
||||||
(:require [reitit.core :as reitit]
|
(:require [reitit.core :as reitit]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
[clojure.set :as set]
|
||||||
[reitit.coercion :as coercion]
|
[reitit.coercion :as coercion]
|
||||||
[goog.events :as e]
|
[goog.events :as e]
|
||||||
[goog.dom :as dom])
|
[goog.dom :as dom])
|
||||||
|
|
@ -38,3 +39,25 @@
|
||||||
(match-by-name router name {}))
|
(match-by-name router name {}))
|
||||||
([router name path-params]
|
([router name path-params]
|
||||||
(reitit/match-by-name router name path-params)))
|
(reitit/match-by-name router name path-params)))
|
||||||
|
|
||||||
|
(defn match-by-name!
|
||||||
|
"Logs problems using console.warn"
|
||||||
|
([router name]
|
||||||
|
(match-by-name! router name {}))
|
||||||
|
([router name path-params]
|
||||||
|
(if-let [match (reitit/match-by-name router name path-params)]
|
||||||
|
(if (reitit/partial-match? match)
|
||||||
|
(if (every? #(contains? path-params %) (:required match))
|
||||||
|
match
|
||||||
|
(let [defined (-> path-params keys set)
|
||||||
|
missing (set/difference (:required match) defined)]
|
||||||
|
(js/console.warn
|
||||||
|
"missing path-params for route" name
|
||||||
|
{:template (:template match)
|
||||||
|
:missing missing
|
||||||
|
:path-params path-params
|
||||||
|
:required (:required match)})
|
||||||
|
nil))
|
||||||
|
match)
|
||||||
|
(do (js/console.warn "missing route" name)
|
||||||
|
nil))))
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
([state k params]
|
([state k params]
|
||||||
(href state k params nil))
|
(href state k params nil))
|
||||||
([{:keys [router history]} k params query]
|
([{:keys [router history]} k params query]
|
||||||
(let [match (rf/match-by-name router k params)
|
(let [match (rf/match-by-name! router k params)
|
||||||
token (match->token history match k params query)]
|
token (match->token history match k params query)]
|
||||||
(token->href history token))))
|
(token->href history token))))
|
||||||
|
|
||||||
|
|
@ -118,6 +118,6 @@
|
||||||
([state k params]
|
([state k params]
|
||||||
(replace-token state k params nil))
|
(replace-token state k params nil))
|
||||||
([{:keys [router history]} k params query]
|
([{:keys [router history]} k params query]
|
||||||
(let [match (rf/match-by-name router k params)
|
(let [match (rf/match-by-name! router k params)
|
||||||
token (match->token history match k params query)]
|
token (match->token history match k params query)]
|
||||||
(.replaceToken history token))))
|
(.replaceToken history token))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue