Skip to content

Instantly share code, notes, and snippets.

@Will-Sommers
Created June 13, 2014 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Will-Sommers/9949efd7c3901ccf8b8d to your computer and use it in GitHub Desktop.
Save Will-Sommers/9949efd7c3901ccf8b8d to your computer and use it in GitHub Desktop.
Flash of last state text
(ns community.location
(:require [community.routes :as routes :refer [routes]]
[sablono.core :as html :refer-macros [html]]))
...
...
(defn init-location! [app-state]
(routes/set-route! app-state)
(.addEventListener js/window "popstate" (partial routes/set-route-and-clear! app-state)))
(ns community.routes
(:require [community.util.routing :as r]))
...
...
(defn set-route! [app]
(let [route (routes (-> js/document .-location .-pathname))]
(swap! app assoc :route-data route)))
(defn set-route-and-clear! [app]
(let [previous-route (get-in @app [:route-data :route])]
(swap! app assoc previous-route nil)
(set-route! app)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment