Last active
April 8, 2021 12:00
-
-
Save nivekuil/466a7524c384dcdeabc15a85823da87e to your computer and use it in GitHub Desktop.
Reitit routes to fulcro legacy routing tree
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
["/user" {:name ::user-main | |
:target 'app.ui.root/UserMain} | |
["/" {:target-ident [:user-main :screen]}] ;; put it here, because reitit will append collections | |
["/:uuid" | |
{:name ::user | |
:target 'app.ui.user/User | |
:target-ident [:user/id :param/uuid] | |
:target-router :router/user | |
:parameters {:path [:map [:uuid uuid?]]}}]] | |
(defn routes->fulcro-tree | |
"Given reitit routes, convert to fulcro legacy routing tree" | |
[routes path] | |
(->> routes | |
(filter vector?) | |
(mapv (fn [route] | |
(if-let [name (:name (get route 1))] | |
(let [newpath (conj path name)] | |
(conj | |
(routes->fulcro-tree route newpath) | |
(fr/make-route | |
name | |
(mapv (fn [name] | |
(->> (reitit/match-by-name router name) | |
:data | |
((fn [{:keys [target-ident target-router]}] | |
(fr/router-instruction target-router target-ident))))) | |
newpath)))) | |
(routes->fulcro-tree route path)))))) | |
(def routing-tree (->> (routes->fulcro-tree routes []) | |
flatten | |
(apply fr/routing-tree))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment