Nest: Modular parent/child route nesting?

Created on 2 Nov 2019  路  4Comments  路  Source: nestjs/nest

Feature Request

Is your feature request related to a problem? Please describe.

Looking for an elegant approach to parent/child nested routes.

Describe the solution you'd like

My experience with decorators is a bit limited, but I was wondering if it would be possible to add functionality so that instead of having @Controller('parent') and @Controller('children') be fully isolated by path, allow the ability to use @Controller('parent/:parentId/children') to define a controller for the 'children' module that would properly nest under parent paths by id.

Ideally this would also allow referencing the 'parentId' parameter within the controller methods when using a single param decorator (@Param('parentId') parentId), and when using it within a DTO param decorator (@Param() params: FindOneChildParams)

If possible, I feel this approach would match the existing API in a very elegant and readable way. It would also prevent a constant bloating situation from putting everything into a parent class or some master route definition file. And it would maintain better modularity by keeping all of the children's routes within their own modules.

Any thoughts? Would this approach be possible given any limitations in decorator functionality, and/or how Nestjs implements its decorators?

needs triage type

Most helpful comment

For now, you can consider using this module: https://github.com/nestjsx/nest-router

@shekohex would you like to create a PR to the core with this module? I think it might be a good idea to merge them :)

All 4 comments

Have you seen this repo https://github.com/nestjsx/nest-router it allows to define parent-child structure for routing. Hope this helps.

Personally I think that keeping decorators as "clean" as possible is a true way.

For now, you can consider using this module: https://github.com/nestjsx/nest-router

@shekohex would you like to create a PR to the core with this module? I think it might be a good idea to merge them :)

@kamilmysliwiec

of course, I'd love to see NestRouterModule as a built-in module :)
I'll try to open a PR asap :+1:

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tronginc picture tronginc  路  3Comments

mishelashala picture mishelashala  路  3Comments

breitsmiley picture breitsmiley  路  3Comments

rafal-rudnicki picture rafal-rudnicki  路  3Comments

anyx picture anyx  路  3Comments