#RouterModule.register is not work

7 messages · Page 1 of 1 (latest)

strong iris
#

delete RouterModule.register is ok,but I just want a route prefix,should I do?

green bolt
#

You still need to put the modules in imports in addition to putting them in the router module

strong iris
# green bolt You still need to put the modules in imports in addition to putting them in the ...

Am I doing the right thing?

import { Module } from '@nestjs/common';
import { RouterModule } from '@nestjs/core';
import { AdminModule } from './app/admin/admin.module';
import { ShopModule } from './app/shop/shop.module';

@Module({
  imports: [
    AdminModule, ShopModule,
    RouterModule.register([
      { path: 'admin', module: AdminModule },
      { path: 'shop', module: ShopModule }
    ]),
  ],
  controllers: [],
  providers: [],
})
export class HttpModule { }
green bolt
strong iris
# green bolt yes, this is correct. now you should see the prefixed routes being registered in...

but lost /admin prefix,I can get /info /login /logout but no access /admin/info....

[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] DbModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] HttpModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] AdminModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] ShopModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:53:59     LOG [InstanceLoader] RouterModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +1343ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [InstanceLoader] CommonModule dependencies initialized +1ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [NestMicroservice] Nest microservice successfully started +5ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [RoutesResolver] CommonController {/}: +23ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [RouterExplorer] Mapped {/login, POST} route +2ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [RouterExplorer] Mapped {/info, GET} route +1ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [RouterExplorer] Mapped {/logout, GET} route +0ms
[Nest] 2784  - 2023/05/04 15:54:00     LOG [NestApplication] Nest application successfully started +3ms
green bolt
#

Hm, I'd need to see more of the code then. What you've shown so far seems correct