I am using Angular 18 with modules as well as standalone components.
In my AppRoutingModule I want to lazy load my standalone components as well as my modules with with loadComponent() and loadChildren().
But if I navigate to a lazy component route /lazyComponent and then refresh the page, after the page refreshes, the component is not loaded.
I use bootstrapModule() in main.ts.
Is it even possible or do i have to transform my modules to standalone components, too and then using bootstrapApplication()?
My code in AppRoutingModule looks like:
{
path: 'orders',
loadComponent: () => import('./orders/orders.component').then(m => m.OrdersComponent)
},
{
path: 'addresses',
loadChildren: () => import('./addresses/addresses.module').then(m => m.AddressesModule)
},
Also if I use
{
path: 'lazyComponent',
component: LazyComponent
},
without lazy loading, refreshing the page doe not load the component.
main.ts:
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
builderfan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Make sure you have basehref
added in index.html
.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My app</title>
<meta charset="UTF-8" />
<base href="/">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
2