Looking for an elegant approach to parent/child nested routes.
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?
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.
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 :)