module-federation-examples icon indicating copy to clipboard operation
module-federation-examples copied to clipboard

[Help] Router Module forRoot Issue with Module Federation

Open dassum03-BH opened this issue 1 year ago • 1 comments

Hi @ScriptedAlchemy,

Shell app using Angular v16, MFE using Angular v15..

MFE has routing module with forRoot():

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

This module is part of exposed standalone component

@Component({ standalone: true, imports: [ AppRoutingModule, SharedModule, BrowserModule, BrowserAnimationsModule, CoreModule ], providers: [ IconService, { provide: APP_INITIALIZER, useFactory: appInitializerFactory, deps: [TranslateService, Injector], multi: true } ], selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] })

Getting error: NG04007: The Router was provided more than once. This can happen if 'forRoot' is used outside of the root injector. Lazy loaded modules should use RouterModule.forChild() instead.

Tried setting forChild with the routing module but that fails with the MFE.

Some help appreciated, thanks!

dassum03-BH avatar May 08 '24 06:05 dassum03-BH

I dont know angular well. You can try contacting Manfred or @zackarychapple @valorkin who know angular much better than myself

ScriptedAlchemy avatar May 09 '24 05:05 ScriptedAlchemy