Open
Description
How to use child routes with parent modules?
The only way I managed to make the child route work was:
// app.routes.ts
export const routes: Routes = [{
path: 'banks',
module: BanksModule,
children: [
{
path: 'account',
module: BankAccountsModule,
},
],
}];
@Module({
imports: [
RouterModule.forRoutes(routes),
BanksModule
BankAccountsModule // Child module is imported directly in AppModule
]
})
export class AppModule {}
app.module
| banks.module
| bankaccounts.module
```ts
@Controller('/banks')
export class BanksController implements CrudController<Bank> {
@Controller()
export class BankAccountsController implements CrudController<BankAccount> {
This http request below return all bank accounts
GET /banks/account
but...
GET /banks/
return:
{
"statusCode": 404,
"message": "Cannot GET /banks",
"error": "Not Found"
}
All other ways return `/banks` but `banks/account` returns:
```json
{
"statusCode": 400,
"message": "Invalid param id. UUID string expected",
"error": "Bad Request"
}
Using nested module
but if you try to use nested module, it will to fail.
@Module({
imports: [
RouterModule.forRoutes(routes),
BanksModule
]
})
export class AppModule {}
@Module({
imports: [
BankAccountsModule // Child module is imported in your parent module
]
})
export class BanksModule {}
app.module
| banks.module
| bankaccounts.module
I already tried to remove and add tags to BankAccount Controller
but nothing makes it work the second way.
I think it is the right way to implement nested routes with parent modules.
But how to make this work with nest-router
?
Update: I think that is any error with Nestjs Crud library.
Metadata
Metadata
Assignees
Labels
No labels