Skip to content

Instantly share code, notes, and snippets.

@njj

njj/foo.cljs Secret

Last active March 1, 2018 20:28
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 njj/cdc852e51e255e99b62946a13565a665 to your computer and use it in GitHub Desktop.
Save njj/cdc852e51e255e99b62946a13565a665 to your computer and use it in GitHub Desktop.
(ns common.routes
(:require [reagent.core :as r :refer [atom]]
[secretary.core :as s :refer-macros [defroute] :include-macros true]
[accountant.core :as a]))
(s/set-config! :prefix "/")
(defn nav []
[:div [:a {:style {:padding "5px"} :href "/"} "Home"]
[:a {:style {:padding "5px"} :href "/spaces/step/1"} "Step One"]
[:a {:style {:padding "5px"} :href "/spaces/step/2"} "Step Two"]])
(defn home []
[:div [nav]
[:div [:h1 "Home"]]])
(defn step-page [step-id]
[:div [nav]
[:div [:h1 (str "Step " step-id)]
[:div [:a {:href "/"} "Home"]]]])
(defonce current-page (r/atom [home]))
(defroute "/" {}
(reset! current-page [home]))
(defroute "/spaces/step/:step-id" {step-id :step-id}
(reset! current-page [step-page {:step-id step-id}]))
(defn router-component []
@current-page)
(defn mount-root []
(r/render [router-component] (.getElementById js/document "app")))
(defn init-routes! []
(a/configure-navigation!
{:nav-handler #(s/dispatch! %1)
:path-exists? #(s/locate-route %1)})
(a/dispatch-current!)
(mount-root))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment