My routing configuration currently reloads Module2 ListComponent on every routing event. However, I want to prevent the list from reloading when a user clicks on a list item within ListComponent.
Specifically, when navigating from module2/route1 to module2/route2, I only want the details outlet to be updated without refreshing the list.
I initially considered changing
<router-outlet name="list"></router-outlet>
to <app-list-component></app-list-component>
. But this approach results in constant reloading of the list component, similar to how it was handled by the router. It seems that the app-routing module reloads everything again. How can I prevent this?
app.component.html
<router-outlet></router-outlet>
app-routing.module.ts
const routes: Routes = [
{
path: 'module1',
loadChildren: () =>
import('./module1/module1.module').then(
(m) => m.Module1Module
),
},
{
path: 'module2',
loadChildren: () =>
import('./module2/module2.module').then(
(m) => m.Module2Module
),
},
module2.component.html
<router-outlet name="list"></router-outlet>
<router-outlet name="details"></router-outlet>
module2-routing.module.ts
const routes: Routes = [
{
path: `route1`,
component: Module2Component,
children:
[
{
path: '',
outlet: 'list',
component: ListComponent,
},
{
path: '',
outlet: 'details',
component: Main1Component
}
],
},
{
path: `route2`,
component: Module2Component,
children:
[
{
path: '',
outlet: 'list',
component: ListComponent,
},
{
path: '',
outlet: 'details',
component: Main2Component
}
],
},
{
path: '',
component: Module2Component,
children:
[
{
path: '',
outlet: 'list',
component: ListComponent,
}
],
},