HC1122
HC1122

Reputation: 414

How to fix RouterModule is undefined

I was setting up lazy loading for my Angular 4 app. I have 18 lazy loaded modules in total, and I noticed that fetching them is taking some time, so I decided to make some kind of loading indicator. After adding it localy to app.component everything was working as it should be. In production I keep getting errors about RouterModule being undefined.

error

Now I can not access none of lazy-loaded modules (those which aren't lazy loaded can be accessed without any troubles).

I tried to remove indicator and things seems to be working again.

I took code from that website https://www.bennadel.com/blog/3505-showing-a-loading-indicator-for-lazy-loaded-route-modules-in-angular-6-1-7.htm

And I assume that problem occurs when adding router to app.component.ts constructor.

Any help for solving that problem would be appreciated.

EDIT1: As requested app.routing.ts routing

Upvotes: 0

Views: 444

Answers (1)

Sumit Parakh
Sumit Parakh

Reputation: 1143

You need to initialize roots in a module like this:-

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

Upvotes: 1

Related Questions