-
-
Save shiftb/21a28328f9fb684cfa8a to your computer and use it in GitHub Desktop.
Example using pushState with ClojureScript + Secretary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; require [goog.events :as events] | |
; import [goog.history Html5History] | |
; [goog Uri] | |
; [goog.history EventType] | |
(defn listen [el type] | |
(let [out (chan)] | |
(events/listen el type | |
(fn [e] (put! out e))) | |
out)) | |
(def history (Html5History.)) | |
(.setUseFragment history false) | |
(.setPathPrefix history "") | |
(.setEnabled history true) | |
(let [navigation (listen history EventType/NAVIGATE)] | |
(go | |
(while true | |
(let [token (.-token (<! navigation))] | |
(secretary/dispatch! token))))) | |
(events/listen js/document "click" (fn [e] | |
(let [path (.getPath (.parse Uri (.-href (.-target e)))) | |
title (.-title (.-target e)) | |
matches-path? (secretary/locate-route path)] | |
(when matches-path? | |
(. history (setToken path title)) | |
(.preventDefault e))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
secretary's API changed and now we use secretary/locate-route instead of secretary/any-matches?