This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-31
Channels
- # announcements (3)
- # babashka (75)
- # beginners (16)
- # calva (124)
- # cider (10)
- # clara (2)
- # clj-kondo (1)
- # cljdoc (4)
- # cljs-dev (14)
- # clojure (104)
- # clojure-australia (4)
- # clojure-czech (5)
- # clojure-europe (14)
- # clojure-germany (48)
- # clojure-nl (4)
- # clojure-serbia (4)
- # clojure-uk (34)
- # clojurescript (60)
- # community-development (16)
- # conjure (12)
- # core-async (34)
- # cursive (42)
- # data-science (7)
- # deps-new (9)
- # depstar (1)
- # emacs (11)
- # events (2)
- # fulcro (15)
- # graalvm (1)
- # inf-clojure (1)
- # jobs (3)
- # jobs-discuss (1)
- # joker (7)
- # juxt (8)
- # lsp (20)
- # malli (42)
- # meander (4)
- # off-topic (5)
- # pathom (2)
- # polylith (13)
- # re-frame (39)
- # reagent (9)
- # reitit (31)
- # releases (2)
- # rewrite-clj (23)
- # shadow-cljs (39)
- # spacemacs (11)
- # specter (6)
- # tools-deps (8)
- # xtdb (12)
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
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.
(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]}}}]])
; (err) Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:19).
; (err) count not supported on this type: Keyword
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.
(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]}}}]])
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.