Open dqdinh opened 9 years ago
(ns frontend.routes
(:require [secretary.core :as sec :refer-macros [defroute]]
[goog.events :as events]
[goog.history.EventType :as EventType]
[frontend.state :refer [change-state]])
(:import goog.history.Html5History))
(defonce history (Html5History.))
;; We can switch routes through this function
(defn trans
[path]
(.setToken history path))
(defroute "/" []
(change-state ...))
(defroute "/post/:slug" {:as params}
(change-state ...))
(defn- on-popstate
[e]
(-> e .-token sec/dispatch!))
(events/listen history EventType/NAVIGATE on-popstate)
;; We can remove # prefix this way
(doto history (.setEnabled true)
(.setPathPrefix "")
(.setUseFragment false))
There is now Accountant which handles this and a bit more as well? Not that that closes this issue.
Would be nice to have a reference example that does not use the # prefix.