Within my app-module I have three feature modules “desktop”, “info”, “shared”. The desktop-module contains the info-module and the shared-module. The info-module contains a imprint-component and the shared-module contains a foot component:
app
├── desktop
│ ├── desktop-routing.module.ts
│ ├── ...
│ ├── info
│ │ ├── ...
│ │ ├── info-routing.module.ts
│ │ └── imprint
│ │ ├── imprint.component.html
│ │ └── ...
│ └── shared
│ ├── foot
│ │ ├── foot.component.html
│ │ └── ...
│ └── shared-component.module.ts
├── ...
└── app-routing.module.ts
The routes in the app-routing.module are:
const routes: Routes = [
{ path: '', redirectTo: 'desktop', pathMatch: 'full' },
{ path: 'desktop', loadChildren: () => import('./desktop/desktop.module').then(m => m.DesktopVersionModule) }
];
I imported the shared module into the desktop-module and into the info-module. And lazy-load the info-module within desktop-routing.module:
const routes: Routes = [
{ path: '', component: DesktopComponent },
{ path: 'info', loadChildren: () => import('./info/info.module').then(m => m.InfoModule) }
];
where info-routing.module:
const routes: Routes = [
{ path: '', component: InfoComponent,
children: [
{ path: 'imprint', component: ImprintComponent },
]
}];
Both, desktop.component.html and the info.component.html contains the selector <app-foot></app-foot>
of the foot-component that includes the foot template into the desktop- and info-template. The foot template contains a link to the imprint-component from the info module:
<span class="default-link" routerLink="info/imprint">Link</span>
If I serve the app, then I can navigate from the desktop-component to the imprint-component by clicking the link in the foot-component. But I can’t navigate from info-component to imprint-component, because the link is not resolved by the framework. To solve it I need to define a shared-routing.module:
const routes: Routes = [
{ path: 'info', loadChildren: () => import('../info/info.module').then(m => m.InfoModule) }
];
If I run now ng serve
everything is working as expected. But ng build
throw exception:
[error] Error [ERR_WORKER_OUT_OF_MEMORY]: Worker terminated due to
reaching memory limit: JS heap out of memory
at [kOnExit] (node:internal/worker:313:26)
at Worker..onexit (node:internal/worker:229:20)
How to adjust routing, so that the system will resolve the link correctly and running not into error above during build process?
I already tried to allocate more memory $ node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build
, but it doesn’t help.