Skip to content

Instantly share code, notes, and snippets.

@milt
Forked from danielsz/pushState.cljs
Last active August 29, 2015 14:08
Show Gist options
  • Save milt/0f047f7a796b4fd1c330 to your computer and use it in GitHub Desktop.
Save milt/0f047f7a796b4fd1c330 to your computer and use it in GitHub Desktop.
(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))]
(when (secretary/any-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