Router Module For Nestjs Framework
RouterModule helps you organize your routes and lets you create a routes tree.
Every 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
see issue #255 .
IMPORTANT: you need Nest > v4.5.10+
npm install nest-router --saveOR
yarn add nest-routerSee how easy it is to set up.
... //imports
const routes: Routes = [
{
path: '/ninja',
module: NinjaModule,
children: [
{
path: '/cats',
module: CatsModule,
},
{
path: '/dogs',
module: DogsModule,
},
],
},
];
@Module({
imports: [
RouterModule.forRoutes(routes), // setup the routes
CatsModule,
DogsModule,
NinjaModule
], // as usual, nothing new
})
export class ApplicationModule {}๐ TIP: Keep all of your routes in a separate file like
routes.ts
In this example, all the controllers in NinjaModule will be prefixed by /ninja and it
has two childs, CatsModule and DogsModule.
Will the controllers of CatsModule be prefixed by /cats? NO!! ๐ฎ
The CatsModule is a child of NinjaModule so it will be prefixed by /ninja/cats/ instead.
And so will DogsModule.
See examples folder for more information.
.
โโโ app.module.ts
โโโ cats
โย ย โโโ cats.controller.ts
โย ย โโโ cats.module.ts
โย ย โโโ ketty.controller.ts
โโโ dogs
โย ย โโโ dogs.controller.ts
โย ย โโโ dogs.module.ts
โย ย โโโ puppy.controller.ts
โโโ main.ts
โโโ ninja
โโโ katana.controller.ts
โโโ ninja.controller.ts
โโโ ninja.module.tsAnd here is a simple, nice route tree of example folder:
ninja
โโโ /
โโโ /katana
โโโ cats
โย ย โโโ /
โย ย โโโ /ketty
โโโ dogs
ย ย โโโ /
ย ย โโโ /puppyNice!
See CHANGELOG for more information.
You are welcome to contribute to this project, just open a PR.
- Shady Khalifa - Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.
