-
-
Save ampersanda/0b64b92fa791d4b89a02b5a63035f24c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example.core | |
(:require [bidi.bidi :as bidi] | |
[goog.events :as events] | |
[clojure.string :as cstr])) | |
(defn start! [on-set-page routes] | |
(letfn [(handle-route [] | |
(let [uri (cstr/replace js/location.hash "#" "")] | |
(->> (if-not (empty? uri) uri "/") | |
(bidi/match-route routes) | |
on-set-page)))] | |
(events/listen js/window "hashchange" handle-route) | |
(handle-route) | |
handle-route)) | |
(defn stop! [handler] | |
(events/unlisten js/window "hashcange" handler)) | |
;; usage | |
(start! on-route-change routes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment