Created
July 10, 2015 13:56
-
-
Save andrewmcveigh/99211f7277271195682d to your computer and use it in GitHub Desktop.
bidi cljs example
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 ... | |
(: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