Skip to content

Instantly share code, notes, and snippets.

@andrewmcveigh
Created July 10, 2015 13:56
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 andrewmcveigh/99211f7277271195682d to your computer and use it in GitHub Desktop.
Save andrewmcveigh/99211f7277271195682d to your computer and use it in GitHub Desktop.
bidi cljs example
(ns ...
(:require [bidi.bidi :as b]))
;;; need the path of uri => /whatever
(defn url-path []
(.getPath (goog.Uri. js/window.location)))
(def routes
["/" [["" :root]
["records" :records]]])
;;; I usually use a multi-method to dispatch to different roots or whatever
;;; but you could handle directly in the above^ routes if you wanted
(defmulti dispatch (fn [{:keys [handler] :as match}] handler))
(defmethod dispatch :root [_]
(call root "root"))
(defmethod dispatch :records [_]
(call root "records"))
(defmethod dispatch :default [_] (dispatch {:handler :root}))
(defn dispatch! []
(dispatch (b/match-route routes (url-path))))
;;; and when your page loads
(dispatch!)
;;; -------
;;; and in reverse
(b/path-for routes :records)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment