π Router Module For Nestjs Framework π―
It still under construction, but here is a simple example of what I Do
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app/app.module';
import { RouterModule, Routes } from '../' // it's what we are building
import { CatsController } from './app/cats/cats.controller';
import { DogsController } from './app/dogs/dogs.controller';
import { NinjaController } from './app/ninja/ninja.controller';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
const routes: Routes = [{
path: '/ninja',
controller: NinjaController,
children: [{
path: '/dogs',
controller: DogsController
}, {
path: '/cats',
controller: CatsController
}]
}]
new RouterModule(NestFactory).forRoutes(routes);
await app.listen(3000);
}
bootstrap();
the result will be
- /ninja
-- /dogs
-- /cats
/ninja -> NinjaController
/ninja/dogs -> DogsController
/ninja/cats -> CatsController
You get the Idea ..