Hi, I am trying to setup nested UI routes with reitit, I want to achieve having following structure:
<TopMenuNav> --> contains top level routes, for example `/home` and `/settings`
<Router>
Then I want to have Settings page with it's own MenuNav and child routes, for example `/settings/users`, `/settings/roles` etc.
<TopMenuNav>
<SettingsMenuNav>
<SettingsChildRouter>
Is there is a way to define it like this:
(def routes
[["/"
{:name ::home
:public? true
:view pages/home-page}]
["/settings"
{:name ::settings
:view pages/settings-page}
["/users" {:name ::users
:view pages/users-page}]
]
])
Then when I push state (rfe/push-state :my-app.routes/users)
it navigates me to the child route.
Basically, I want to achieve having nested routes with it’s own shared menus without defining it inside each child component.
I couldn’t find something similar, any help appreciated.Currently the error I have is missing route :my-app.routes/users
the router doesn’t recognise nested routes definitions.
I also tried set it up like this:
(def routes
[["/"
{:name ::home
:public? true
:view pages/home-page}]
["/settings"
{:name ::settings
:view pages/settings-page
:router (rf/router [
["/users" {:name ::users
:view pages/users-page}]
])
}]
])
The app is started this way:
(rfe/start!
(rf/router routes {:data {:coercion rss/coercion}})
set-route!
{:use-fragment true})
I don't have a solution to your problem, but have you checked out https://github.com/metosin/reitit/blob/master/doc/advanced/composing_routers.md#nesting-routers ? your latter example with :router
looks similar to what's proposed in the doc, but the docs also describe a recursive-match-by-path
method for resolving such nested routes
Yes, I saw it, and used as it was suggested there with :router
however, I don’t use explicitly match-by-path
, in my case I am just passing the router to the rfe/start!
which is reitit.frontend.easy
and then I use (rfe/push-state :my-app.routes/users)
to navigate to routes
Is there is an example of using nested routes with recursive-match-by-path
for front end, since I have found only passing the router to reitit.frontend.easy/start!
and match being done somewhere underneath.
Okay, I'm having some strange behaviour...
I have this defined as a route:
(defn routes
[app-config]
["/session" {:parameters {:query specs/company-id}}
["" {:get {:handler (create app-config)
:parameters {:query specs/create}
:swagger {:produces [session-create-api-version]}}}]])
firing up the app, I get this error:
; (err) Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:19).
; (err) count not supported on this type: Keyword
if I comment out the :parameters
on the :get
, it starts up
which leads me to suspect that my spec is wrong, yet it's very simple:
(def create [:map
{:closed true}
[:repId string?]
[:clientPhoneNumber string?]])
No idea why this is failing to start, if :parameters
is part of the :get
The m/validate
passes: (m/validate create {:repId "ac56a265-6b79-4da2-8438-c5bcf0bb0798" :clientPhoneNumber "1234567890"}) ;; true
@dharrigan Reitit isn't currently able to merge Malli schemas in route-data: https://github.com/metosin/reitit/issues/422 Probably something related to this.
oooh
thank you
I shall adapt 🙂
It seems to be okay if the key is different, i.e.,
(defn routes
[app-config]
["/session" {:parameters {:query specs/company-id}}
["" {:post {:handler (create app-config)
:parameters {:body specs/create}
:swagger {:produces [session-create-api-version]}}}]])
that works, since parameters is a query and a body
Yeah it can merge :parameters
map using normal merge. Just merging two Mallis requires malli.core/merge
call, which Reitit doesn't yet know how to do.
Other ways to avoid is to just move all parameters to the route directly. And you can also use ^:replace
on route to avoid merging if there is some schemas on the tree.
thank you 🙂
btw, I was thinking of inviting the chat logging bot (I think it's a zulip bot) to this channel, as I don't see it logged, therefore helpful messages disappear after a while (I was scrolling back to see if I could find information on the empty map handling)
I suppose that would be okay?
Sure
actually, they are already here - the zulip bot and the log bot
so all is well 😄