Eagerly module loading causes some of the template to disappear

53 Views Asked by At

I have one eagerly loading module (app-routing.module.ts hosting HomeComponent) and one lazy loading module (my-routing.module.ts). My problem is that when I press Experiment button from my test.component.html the whole line with that button disappears.

My app-routing.module.ts looks like this:

const myModule = () => import('./my-routing/my-routing.module').then(x => x.MyRoutingModule);
const routes: Routes = [
  { path: '', component: TestComponent },
  { path: 'experiment', /* component: ListComponent, outlet: "outlet1" */loadChildren: myModule },
  {
    path: 'home',
    component: HomeComponent, outlet: "outlet1"
  },
];

My my-routing.module.ts looks like this:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ListComponent } from '../list.component';
import { TestComponent } from '../test/test.component';

const routes: Routes = [

  
  { path: 'test', component: ListComponent, outlet: "outlet2" },

];

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

My app.component.html looks like this:

<div style="text-align:center">
  <h1>
    Welcome to {{title}}!!
  </h1>
  <nav>

</nav>
  <router-outlet></router-outlet>
  <div >
    <button type="button" class="btn btn-primary">Primary</button>
    <button type="button" class="btn btn-secondary">Secondary</button>
    <button type="button" class="btn btn-success">Success</button>
    <button type="button" class="btn btn-danger">Danger</button>
    <button type="button" class="btn btn-warning">Warning</button>
    <button type="button" class="btn btn-info">Info</button>
    <button type="button" class="btn btn-light">Light</button>
    <button type="button" class="btn btn-dark">Dark</button>

    <button type="button" class="btn btn-link">Link</button>
  </div>
</div>
<router-outlet name="outlet1"></router-outlet>
<router-outlet name="outlet2"></router-outlet>

and finally my test.component.html looks like this:

<div class="container">
  <div class="row">
    <div class="col-2">
      <a [routerLink]="[{ outlets:{ outlet1: ['home'] }}]" routerLinkActive="active"><button type="button" class="btn btn-primary">
          Home</button></a>
    </div>
    <div class="col-1">
      <a [routerLink]="['experiment', { outlets:{ outlet2: ['test'] }}]"><button type="button" class="btn btn-primary">
          Experiment</button></a>
    </div>

  </div>
</div>
0

There are 0 best solutions below