0

I have created routes in app.routes.ts file and imported in app.module.ts file. Strangely I'm getting an error saying that RouterModule.forRoot() was called twice

Error In Console

export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Solved: Inner Modules I have used Routermodule.forRoot() changed to Routermodule.forChild(). working fine. Thanks – Arun Kumar Aug 27 '18 at 17:59

2 Answers2

0

use forChild for lazy module routing and exports RouterModule

Stackblitz Demo

imports:[
    RouterModule.forChild(routes)
],
exports:[
    RouterModule
]
Krishna Rathore
  • 9,389
  • 5
  • 24
  • 48
0

The error says it all.

There should be only one RouterModule.forRoot(routes) in your application, which should be on the root module of your application (Usually AppModule). All the other child modules (particularly lazy loading modules) should import RouterModule.forChild(routes).

See the diff here

Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98