Last active
April 16, 2019 19:08
-
-
Save Deraen/4038244e3cb47d9dcb6b6e59d9e1b96a to your computer and use it in GitHub Desktop.
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
(defn router-component [match] | |
(let [[view-component & nested-view-components] (:views match)] | |
(if view-component | |
[view-component (assoc match :views nested-view-components)]))) | |
(defn topics-view [match] | |
[:div | |
[:div "List of topics..."] | |
;; Nested router, renders nothing or topic-view if in :topic | |
[router-component match]]) | |
(def topic-view [match] | |
[:h1 "Topic"]) | |
(def router | |
(rf/router | |
[["/" {:name :frontpage | |
:views [frontpage-view]}] | |
["/topics" | |
{:views [topics-view]} | |
["" | |
{:name :topics} | |
["/:id" | |
{:name :topic | |
:viwes [topic-view]}]]])) | |
(defn main-view [match] | |
;; for :topic-view, :views is [topics-view topic-view] | |
;; first router renders topics-view, and calls the component with match with updated :views list | |
;; nested router renders the next view component etc. | |
[router-component match]) | |
;; Notes: | |
;; All components need to now take match as parameter | |
;; Could be possible to use React context or something |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment