Last active
July 26, 2019 18:03
-
-
Save oconn/7f6ea67d92e0b6aaedf719c54c2cacb8 to your computer and use it in GitHub Desktop.
re-frame-routing 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
;; Container views (usally in seperate views | |
(defn home | |
[{:keys [route-key path-parms query-params]}] | |
[:div "Home"]) | |
(defn sign-in | |
[{:keys [route-key path-parms query-params]}] | |
[:div "Sign In"]) | |
(defn not-found | |
[{:keys [route-key path-parms query-params]}] | |
[:div "Page not found"]) | |
;; app.router.core | |
(defmulti containers identity) | |
(defmethod containers | |
:home [] [home]) | |
(defmethod containers | |
:sign-in [] [sign-in]) | |
;; CATCH-ALL ROUTE | |
(defmethod containers | |
:default [] [not-found]) | |
(defn router [] | |
(let [route-key (re-frame/subscribe [:router/route]) | |
path-parms (re-frame/subscribe [:router/route-params]) | |
query-params (re-frame/subscribe [:router/route-query])] | |
(fn [] | |
[containers @route-key]))) | |
;; app.core | |
(def routes ["/" {"" :home | |
"/home" :home | |
"/sign-in" :sign-in}]) | |
(rfr/register-subscriptions) | |
(rfr/register-events {:routes routes}) | |
(defn render | |
[] | |
[:div | |
;; Some other content (usually navbar) | |
[router]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment