Accessing Parent Params in Nested .route() Handlers #4118
kevinsimper
started this conversation in
General
Replies: 1 comment
-
This would be nice if it were somehow built in My workaround is just to stick the In the post logic:
Then in the nested routes you can do
This won't be typed by default, but if you define the
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Hono community,
When using nested routes via .route(), handlers in the child route don't seem to have direct access to parameters defined in the parent route.
Example:
Because postId isn't available in commentsApp, a common workaround is to restructure the routes like this:
Question:
Is this restructuring (e.g., /posts/comments/:postId instead of /posts/:postId/comments) the idiomatic way in Hono to handle nested resources needing parent IDs when using separate Hono instances with .route()? Or is there a better pattern to access parent parameters directly within the nested route handlers?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions