Hey guys! I am still a bit new into the Clojure(script) world. Perhaps someone can help me.
I have some routes for frontend routing using reitit.frontend.easy
, but I am failing to extract the route parameters for a controller.
Here is some code:
(def router
(rtf/router
["/market"
[""
{:name ::main-view}]
["/:game-id"
{:name ::game-view}
["/:category-id"
[""
{:name ::category-view}]
["/:subcategory-id"
[""
{:name :subcategory-view
:view mkv/variants-page
:controllers
{:parameters {:path [:game-id]}
:start (fn [parameters]
(js/console.log "Entering subcategory view")
(info parameters)
(rf/dispatch [::rg/query
mke/get-variants-by-subcategory-query
{:subcategory "weapon_ak47"
:lang "en_us"}
[::mke/fetch-variants-by-subcategory-success]]))}}]
["/:variant-id"
{:name :variant-view
:view mkv/asset-page
:controllers
[{:start (fn [& params] (info "Entering variant view"))}
:stop (fn [& params] (info "Exiting variant view"))]}]]]]
["/sell"
{:name ::inventory-sell}]
["/filters"
{:name ::advanced-filtering}]]))
(defn init-routes []
(debug "initializing routes")
(let [current-route (rf/subscribe [::current-route])]
(rtfe/start! router
(fn [route history]
(info route)
(rfc/apply-controller (:controllers (:data route)) :start )
(rf/dispatch-sync [::set-current-route route]))
{:use-fragment false})
(r/render [mkv/market-main current-route]
(dom/getElement "market-container"))))
When the route matches on the /:subcategory-id
and then ""
, the parameters are always nil when I print inside the route controller.
I want to retrieve the :game-id
parameter, from the previously ancestor ::game-view
, and use it to retrieve some information.
I tried searching for the docs but couldn't find an example like the nested structure like the one I am using.