Does anyone have any examples of nested routes with more than 2 levels of nesting?
I'm surely doing something syntactically wrong but I can't quite figure it out ...
For example, why doesn't the other nesting work here?
(def some-routes
["/" {}
["" {:name :legacy}]
["-/team" {:name :main}
["/:team-id"] {:name :team}]])
(r/route-names (r/router some-routes)) ;; => [:legacy :main]I don't understand why :team is not there.
I think there’s a dash before /team
There is intended to be -
I want the URL to be like "/-/team/12312"
Oh. Sorry.
Oh, no apology needed, certainly - I'm sure I'm making a mistake here, but I've combed the reitit docs and examples and even at the REPL I'm not managing to see why (in terms of syntax) the second level of nesting doesn't result in :team being part of what route-names returns.
Perhaps the {:name :team} should be inside the ["/:team-id"] array?
It’s because of the way reitit flattens routes. You need a "" route.
["-/team" {:options-shared-by :all-children}
["" {:name :main}]
["/:team-id" {:name :team}]]Thank you @michaeljweaver - but how to have a different route for a plain / ?
(That's why I tried to show 3 levels in my example)
Ah --
(def routes
["/" {}
["" {:name :legacy}]
["-/team" {:options-shared-by :all-children}
["" {:name :main}]
["/:team-id" {:name :team}]]])That appears to work, at least from the standpoint of the route names.
I didn’t reproduce your full tree, just that one branch.
Ok - thank you for your help!
I wish I understood this better - maybe reading the reitit code is the only path.
It’s tripped me up before too, because I think of a tree with parents and children, but reitit flattens everything and only preserves the children.
So if you want a route that represents the parent, you have to use "".
There is some other function, besides route-names, that will let you examine the final generated routes?
I'm only trying to do this nested stuff because I wanted this sort of hierarchal controller start/stop behavior -
But can I get the equivalent behavior by just writing this flat?
Because I'm trying to add one level further (like, with "/:foo-id") and I'm still in the same boat as before,
but somewhat unable to generalize your advice.
I think you can, but I think nesting is better. You will have options you want for some children, but not others, and nesting is really handy for that.
Ah I have an idea.
I’ve used this to examine my final routes:
(comment
(do
(require '[reitit.core :as r])
(r/routes (reitit/router routes {:conflicts nil})))
)Thank you @michaeljweaver!