             [goog.events :as events])
   (:import [goog.history Html5History EventType]))
 
+;; Make the Html 5 History API work
+(defn get-token []
+  (str js/window.location.pathname js/window.location.search))
+
+(defn make-history []
+  (doto (Html5History.)
+    (.setPathPrefix (str js/window.location.protocol
+                         "//"
+                         js/window.location.host))
+    (.setUseFragment false)))
+
+(defn handle-url-change [e]
+  ;; log the event object to console for inspection
+  (js/console.log e)
+  ;; and let's see the token
+  (js/console.log (str "Navigating: " (get-token)))
+  ;; we are checking if this event is due to user action,
+  ;; such as click a link, a back button, etc.
+  ;; as opposed to programmatically setting the URL with the API
+  (when-not (.-isNavigation e)
+    ;; in this case, we're setting it
+    (js/console.log "Token set programmatically")
+    ;; let's scroll to the top to simulate a navigation
+    (js/window.scrollTo 0 0))
+  ;; dispatch on the token
+  (secretary/dispatch! (get-token)))
+
+(defonce history (make-history))
 (defonce chunks-state (atom '()))
 
 ;; ---

      (for [item chunk-row]
        [chunk-card item])])])

(defn header
  []
  [:nav.navbar.navbar-light.bg-faded
   [:div.container
    [:a.navbar-brand {:href "#"} "bitfondue"]
    [:ul.nav.navbar-nav
     [:li.nav-item
      [:a.nav-link {:href "#features"} "Features"]]
     [:li.nav-item
      [:a.nav-link {:href "#pricing"} "Pricing"]]
     [:li.nav-item
      [:a.nav-link {:href "#about"} "About"]]]
    [:ul.nav.navbar-nav.pull-right
     [:li.nav-item
      [:a.nav-link {:href "#login"} "Login"]]
     [:li.nav-item
      [:a.nav-link {:href "#register"} "Register"]]]]])

(defn footer
  []

  (reagent/render-component
   [page-component]
   application))

(defroute "/" [] (page home-anonymous))
(defroute "/dashboard" [] (page home-authenticated))
