@@ 22,6 22,12 @@
:handler #(reset! path (response-handler %))}))
;; -------------------------
+;; Utils
+
+(defn mount [component]
+ (r/render component (.getElementById js/document "app")))
+
+;; -------------------------
;; Components
(defn navbar []
@@ 32,8 38,9 @@
[:input {:id "bmenub" :type "checkbox" :class "show"}]
[:label.icon-g {:for "bmenub" :class "burger pseudo button"} "menu"]
[:div.menu
- [:a.pseudo.button {:href "#"} "About"]
- [:a.pseudo.button {:href "#"} "Analytics"]]])
+ [:a.button {:href ""} "Home"]
+ [:a.pseudo.button {:href "#about"} "About"]
+ [:a.pseudo.button {:href "#analytics"} "Analytics"]]])
(defn header []
[:header
@@ 138,12 145,35 @@
[input]
[graph]])
+(defn about-page []
+ [:body [navbar]
+ [:h1 "About Page"]])
+
+(defn analytics-page []
+ [:body [navbar]
+ [:h1 "Analytics Page"]])
+
;; -------------------------
-;; Initialize app
+;; Routing
+
+(def routes
+ {"" front-page
+ "#about" about-page
+ "#analytics" analytics-page})
+
+(defn handle-routes [routes event]
+ (let [hash (.-location.hash js/window)
+ page (get routes hash (get routes ""))]
+ (.history.replaceState js/window {} nil hash)
+ (mount page)))
-(defn mount-root []
- (r/render [front-page] (.getElementById js/document "app")))
+(defn setup-router [routes]
+ (.addEventListener js/window "hashchange" #(handle-routes routes %))
+ (handle-routes routes nil))
+
+;; -------------------------
+;; Initialize app
(defn init! []
- (mount-root))
+ (setup-router routes))