-
Notifications
You must be signed in to change notification settings - Fork 260
Nesting routes
James Reeves edited this page Jun 19, 2014
·
12 revisions
The context macro provides a way of giving a set of routes a common prefix:
(defroutes user-routes
(context "/user/current" []
(GET "/profile" [] ...)
(GET "/posts" [] ...)))Route parameters may be added to the context, just like a normal route:
(defroutes user-routes
(context "/user/:user-id" [user-id]
(GET "/profile" [] ...)
(GET "/posts" [] ...)))Because routes are closures, the user-id symbol is available to use in the two sub routes.
However, if your inner routes are defined separately, you need to manually pass any bound parameters from the context. For example:
(defn inner-routes [user-id]
(routes
(GET "/profile" [] ...)
(GET "/posts" [] ...)))
(defroutes user-routes
(context "/user/:user-id" [user-id]
(inner-routes user-id)))