-
-
Save gf3/5df04fc4ed3a8bc4f84a to your computer and use it in GitHub Desktop.
This file contains 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
;; History | |
(def *h* (atom nil)) | |
(defn start-history! | |
"HTML5 History API FTW!" | |
[uri-path] | |
(compare-and-set! *h* nil (new goog.history.Html5History)) | |
(.setUseFragment @*h* false) | |
(.setPathPrefix @*h* "") | |
(.setEnabled @*h* true) | |
(events/listen @*h* | |
event-type/NAVIGATE | |
(fn [e] | |
(secretary/dispatch! (scm-js.common/get-current-path))))) | |
(defn ^:export navigate | |
"Navigate to a path including a page title" | |
[token title] | |
(. @*h* (setToken token title))) | |
(defn start-click-listener! | |
"Intercept clicks and prevent default if we have a matching route" | |
[] | |
(delegate ($ js/document) "a" :click (fn [e] | |
(this-as me | |
(when (secretary/any-matches? me.pathname) | |
(.preventDefault e) | |
(navigate me.pathname (or e.currentTarget.title "SCM Module"))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment