{"id":13598725,"url":"https://github.com/nestjsx/nest-router","last_synced_at":"2026-01-03T12:11:36.183Z","repository":{"id":40777866,"uuid":"119735212","full_name":"nestjsx/nest-router","owner":"nestjsx","description":"Router Module For Nestjs Framework 🚦 🚀","archived":false,"fork":false,"pushed_at":"2023-03-08T00:16:23.000Z","size":2258,"stargazers_count":618,"open_issues_count":104,"forks_count":36,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-28T15:11:15.333Z","etag":null,"topics":["addons","nestjs","typescript","utilities"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nestjsx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-31T19:49:11.000Z","updated_at":"2025-02-26T03:36:49.000Z","dependencies_parsed_at":"2023-09-27T03:08:55.128Z","dependency_job_id":null,"html_url":"https://github.com/nestjsx/nest-router","commit_stats":{"total_commits":127,"total_committers":11,"mean_commits":"11.545454545454545","dds":0.3464566929133859,"last_synced_commit":"78d907258e8e3012eb4e29b8c63e6acd44d90887"},"previous_names":["shekohex/nest-router"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnest-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnest-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnest-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnest-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nestjsx","download_url":"https://codeload.github.com/nestjsx/nest-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208190,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addons","nestjs","typescript","utilities"],"created_at":"2024-08-01T17:00:55.432Z","updated_at":"2026-01-03T12:11:36.150Z","avatar_url":"https://github.com/nestjsx.png","language":"TypeScript","funding_links":[],"categories":["资源"],"sub_categories":["组件和库"],"readme":"# Nest Router :vertical_traffic_light:\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/shekohex/nest-router.svg)](https://greenkeeper.io/) [![Build Status](https://travis-ci.org/shekohex/nest-router.svg?branch=master)](https://travis-ci.org/shekohex/nest-router) [![npm version](https://badge.fury.io/js/nest-router.svg)](Https://www.npmjs.com/package/nest-router) [![Coverage Status](https://coveralls.io/repos/github/shekohex/nest-router/badge.svg?branch=master)](https://coveralls.io/github/shekohex/nest-router?branch=master)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fshekohex%2Fnest-router.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fshekohex%2Fnest-router?ref=badge_shield)\n\nRouter Module For [Nestjs](https://github.com/nestjs/nest) Framework\n\n## Important Note\n\nAs of Nestjs `v8.0.0` This module got added into the `@nestjs/core`.\nsee the [docs](https://docs.nestjs.com/recipes/router-module)\nwith that being said, this package is still maintained (for now).\n\n## Quick Overview\n\n`RouterModule` helps you organize your routes and lets you create a routes tree.\n\n### How ?\n\nEvery module could have a path property. That path will be a prefix for all controllers in this module. If that module has a parent, it will be a child of it and again all controllers in this child module will be prefixed by `parent module prefix` + `this module prefix`\n\n\u003e see issue [#255](https://github.com/nestjs/nest/issues/255) .\n\n## Install\n\nIMPORTANT: you need Nest \u003e v4.5.10+\n\n```bash\nnpm install nest-router --save\n```\n\nOR\n\n```bash\nyarn add nest-router\n```\n\n## Setup\n\nSee how easy it is to set up.\n\n```ts\n... //imports\nconst routes: Routes = [\n    {\n      path: '/ninja',\n      module: NinjaModule,\n      children: [\n        {\n          path: '/cats',\n          module: CatsModule,\n        },\n        {\n          path: '/dogs',\n          module: DogsModule,\n        },\n      ],\n    },\n  ];\n\n@Module({\n  imports: [\n      RouterModule.forRoutes(routes), // setup the routes\n      CatsModule,\n      DogsModule,\n      NinjaModule\n  ], // as usual, nothing new\n})\nexport class ApplicationModule {}\n```\n\n\u003e :+1: TIP: Keep all of your routes in a separate file like `routes.ts`\n\nIn this example, all the controllers in `NinjaModule` will be prefixed by `/ninja` and it\nhas two childs, `CatsModule` and `DogsModule`.\n\nWill the controllers of `CatsModule` be prefixed by `/cats`? NO!! :open_mouth:\nThe `CatsModule` is a child of `NinjaModule` so it will be prefixed by `/ninja/cats/` instead.\nAnd so will `DogsModule`.\n\n\u003e See examples folder for more information.\n\n#### Example Folder Project Structure\n\n```bash\n.\n├── app.module.ts\n├── cats\n│   ├── cats.controller.ts\n│   ├── cats.module.ts\n│   └── ketty.controller.ts\n├── dogs\n│   ├── dogs.controller.ts\n│   ├── dogs.module.ts\n│   └── puppy.controller.ts\n├── main.ts\n└── ninja\n    ├── katana.controller.ts\n    ├── ninja.controller.ts\n    └── ninja.module.ts\n```\n\nAnd here is a simple, nice route tree of `example` folder:\n\n```bash\nninja\n    ├── /\n    ├── /katana\n    ├── cats\n    │   ├── /\n    │   └── /ketty\n    ├── dogs\n        ├── /\n        └── /puppy\n```\n\nNice!\n\n#### Params in nested routes\n\nIn a standard REST API, you probably would need to add some params to your nested routes. Here is an example of how you can achieve it:\n\n```ts\n... //imports\nconst routes: Routes = [\n    {\n      path: '/ninja',\n      module: NinjaModule,\n      children: [\n        {\n          path: '/:ninjaId/cats',\n          module: CatsModule,\n        },\n        {\n          path: '/:ninjaId/dogs',\n          module: DogsModule,\n        },\n      ],\n    },\n  ];\n```\n\nThe `ninjaId` param will be available inside `CatsModule` controllers and `DogsModule` controllers. Please, find the [instruction how to handle params in the official documentation](https://docs.nestjs.com/controllers#route-parameters). It might be a good practice to use a [pipe for transformation use case](https://docs.nestjs.com/pipes#transformation-use-case) to have an access to `ninja` object instead of just id.\n\n\n#### Resolve Full Controller Path:\nNestjs dosen't resolve or take into account `MODULE_PATH` metadata when it is coming to resolve Controller path in Middleware resolver for example, so that i introduced a new fancy method `RouterModule#resolvePath` that will resolve the full path of any controller so instead of doing so:\n\n```ts\nconsumer.apply(someMiddleware).forRoutes(SomeController);\n``` \nyou should do\n\n```ts\nconsumer.apply(someMiddleware).forRoutes(RouterModule.resolvePath(SomeController));\n``` \n\nsee [#32](https://github.com/shekohex/nest-router/pull/32) for more information about this.\n\n## CHANGELOG\n\nSee [CHANGELOG](CHANGELOG.md) for more information.\n\n## Contributing\n\nYou are welcome to contribute to this project, just open a PR.\n\n## Authors\n\n* **Shady Khalifa** - _Initial work_\n\nSee also the list of [contributors](https://github.com/shekohex/nest-router/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fshekohex%2Fnest-router.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fshekohex%2Fnest-router?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsx%2Fnest-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnestjsx%2Fnest-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsx%2Fnest-router/lists"}