Open
Description
Hello,
it might be interesting to add names to each route, to use the name in the controllers and not a path.
So we could easily change a route without having to go into the controller.
In module:
const routes: Routes = [
{
path: '/api',
name: 'api',
children: [
{
path: '/cats',
module: CatsModule,
name: 'cats',
},
{
path: '/cats/:id',
module: CatsModule,
name: 'catsById',
},
{
path: '/dogs',
module: DogsModule,
name: 'dogs',
},
],
},
];
In controller:
// ...
@Controller()
export class CatsController {
private cats: string[] = [];
@Get('cats')
sayHello() {
return `Hello From CatsController`;
}
@Get('catsById')
getCat(@Param('catId') id: string) {
const idx = parseInt(id, 10) || 0;
return { cat: this.cats[idx - 1] || null };
}