Fork me on GitHub
#reitit
<
2022-06-15
>
Nedeljko Radovanovic13:06:02

Hey people 👋 Is there a way to store data trough nested routes?

(def routes
  ["/" {:coercion reitit.coercion.spec/coercion}
   ["" {:name        :route/home
        :controllers [{:identity identity}]
        :doc         "Home page"}]
   ;; -----
   ["ad-type/{ad-type}"            
;; Is there a way to nest these two routes, I dont want to repeat myself with passing :ad-type as path-param, this looks like code repetition and i dont want that...
    {:name        :route/ad-type
     :path-params {:ad-type keyword?}
     :doc         "Ad-type page"
     :controllers [{:start      #(js/console.log "START: " "ad-type/:ad-type/grains-kind")
                    :stop       #(js/console.log "STOP: " "ad-type/:ad-type/grains-kind")}]}]
   ["ad-type/{ad-type}/grains-kind/{grains-kind}"
    {:name        :route/choice
     :path-params {:grains-kind keyword?
                   :ad-type keyword?}
     :doc         "Ad-type page"
     :controllers [{:start      #(js/console.log "START: " "ad-type/:ad-type/grains-kind/:grains-kind")
                    :stop       #(js/console.log "STOP: " "ad-type/:ad-type/grains-kind/:grains-kind")}]}]])
Here i have 2 routes that are similar and i repeat myself, I would like to nest them and accumulate data trough nesting, every route needs to show different view so new data can be accumulated.... There is a option for me to create 2 more routes ( ad-type has only 2 choices, I could extract :ad-type via regex or something and then convert it to the data-type i need...) but I wouldn't like to hard code it if there is no need for that, nesting would look much cleaner.. Thank you in advance, any info or reference to a good documentation could help.. 😄

juhoteperi13:06:12

["ad-type/{ad-type}"
   {:shared-data "foo"
   :controllers [shared-controller]}
   ["" {:name :route-ad-type ...}]
   ["/grains/kind/{grains-kind}" {...}]]

Nedeljko Radovanovic19:06:14

Thank you for response. 😁