mirror of
https://github.com/metosin/reitit.git
synced 2026-02-03 11:00:34 +00:00
Use setToken in a click handler and add set-token function
This commit is contained in:
parent
6b8ebdebe6
commit
2152bf0345
1 changed files with 13 additions and 3 deletions
|
|
@ -55,9 +55,9 @@
|
||||||
(= 0 (.-button e))
|
(= 0 (.-button e))
|
||||||
(reitit/match-by-path router (.getPath uri)))
|
(reitit/match-by-path router (.getPath uri)))
|
||||||
(.preventDefault e)
|
(.preventDefault e)
|
||||||
(.replaceToken history (path->token history (str (.getPath uri)
|
(.setToken history (path->token history (str (.getPath uri)
|
||||||
(if (seq (.getQuery uri))
|
(if (seq (.getQuery uri))
|
||||||
(str "?" (.getQuery uri))))))))))
|
(str "?" (.getQuery uri))))))))))
|
||||||
|
|
||||||
(impl/goog-extend
|
(impl/goog-extend
|
||||||
^{:jsdoc ["@constructor"
|
^{:jsdoc ["@constructor"
|
||||||
|
|
@ -136,7 +136,17 @@
|
||||||
token (match->token history match k params query)]
|
token (match->token history match k params query)]
|
||||||
(token->href history token))))
|
(token->href history token))))
|
||||||
|
|
||||||
|
(defn set-token
|
||||||
|
"Sets the new route, leaving previous route in history."
|
||||||
|
([state k params]
|
||||||
|
(set-token state k params nil))
|
||||||
|
([{:keys [router history]} k params query]
|
||||||
|
(let [match (rf/match-by-name! router k params)
|
||||||
|
token (match->token history match k params query)]
|
||||||
|
(.setToken history token))))
|
||||||
|
|
||||||
(defn replace-token
|
(defn replace-token
|
||||||
|
"Replaces current route. I.e. current route is not left on history."
|
||||||
([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]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue