Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML5 history Example #74

Open
dqdinh opened this issue Sep 1, 2015 · 2 comments
Open

Add HTML5 history Example #74

dqdinh opened this issue Sep 1, 2015 · 2 comments

Comments

@dqdinh
Copy link

dqdinh commented Sep 1, 2015

Would be nice to have a reference example that does not use the # prefix.

@andromorv
Copy link

(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))

@BorisKourt
Copy link

There is now Accountant which handles this and a bit more as well? Not that that closes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants