角形,在页面中的哪里放置路由器出口

时间:2019-08-13 13:22:17

标签: javascript angular angular-ui-router router-outlet

我有一个Angular 8应用程序,并且尝试使延迟加载工作。

谷歌搜索很多。

所以看来一切正常。但没有正确的方法。因为我有一个页面,并且在该页面上,所以您具有图标,您将在其中被重定向到具有该ID的单独页面。

因此html模板如下所示:

 <app-topbar header="Hulpbronnen overzicht">
</app-topbar>
<!-- <app-vital10-page header="Hulpbronnen overzicht">
</app-vital10-page> -->

<div class="inner-body">
  <app-is-loading *ngIf="!resourcesLoaded" message="Hulpbronnen worden geladen"></app-is-loading>

  <app-no-entries
  *ngIf="!hasResources && resourcesLoaded"
  type="hulpbronnen"
  [loads]="resourcesLoaded"
  ></app-no-entries>
  <div class="mobile-resource-filter" (click)="showFilterForMobile = true" *ngIf="allResourceThemesKeys.length > 0">
    <span class="fa fa-filter"></span>
  </div>
  <div class="resources">
    <div class="resources-main">
      <div class="resource-row" *ngFor="let key of resourceThemesKeys" [@fade]>
        <h3 class="resource-row-title">{{ key }}</h3>
        <div class="resource-items">
          <app-resource-item *ngFor="let item of resourceThemes[key]" [resource]="item">

          </app-resource-item>

        </div>
      </div>
    </div>
    <div
    class="resources-side"
    *ngIf="allResourceThemesKeys.length > 0"
    [ngClass]="{'stuck-to-top': showFilterForMobile}"
    >
    <div class="resources-filter resource-row">
      <h3 class="resources-header resources-header-filter resource-row-title">Thema Filter</h3>
      <div class="resources-filter-body">
        <div class="resource-filter-item">
          <label for="filter-all" class="resources-filter-label">
              <input
              type="checkbox"
              class="resources-filter-input resources-filter-input-all"
                id="filter-all"
                (change)="filterAll(allOn)"
                [checked]="!allOn"
                />
                Filter alles
              </label>
              <div class="resource-filter-close" *ngIf="showFilterForMobile">
                <button type="button" class="button" (click)="showFilterForMobile = false">Sluit</button>
              </div>
            </div>
            <div class="resources-filter-item">
              <label for="{{ theme }}" class="resources-filter-label" *ngFor="let theme of allResourceThemesKeys">
                <input
                type="checkbox"
                id="{{ theme }}"
                class="resources-filter-input"
                [checked]="resourceThemesKeys.indexOf(theme) !== -1"
                (change)="handleFilterChange(theme)"
                />
                {{ theme }}
              </label>

            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <router-outlet></router-outlet>


路由器模块如下所示:

const ResourceRouters: Routes = [
  {
    path: '',
    component: ResourcePageComponent,
    children: [
      {path: '', pathMatch: 'full', canActivate: [AuthGuard] },
      {path: 'detail/:hulpbronId', component: ResourceDetailComponent, canActivate: [AuthGuard]}
    ]
  }
];


@NgModule({

  imports: [
    RouterModule.forChild(ResourceRouters)
  ],
  exports: [RouterModule]



})

,主网址如下:

http://localhost:4200/hulpbronnen

,例如,您的ID为:

http://localhost:4200/hulpbronnen/detail/6688089b-9794-4169-8569-260d427bed03

但是现在,该ID的内容将在主页上呈现,而不是在其自己的组件上呈现。

必须是什么

在app.routes.ts中,我这样子:

{path: 'hulpbronnen', loadChildren: () => import('./resource/resource.module').then(m => m.ResourceModule)},

所以我的问题是:我必须把

放在哪里
<router-outlet></router-outlet>

谢谢

这样子页面才能正确显示

1 个答案:

答案 0 :(得分:1)

如果适合您,可以尝试以下方法:

创建一个新组件ResourceIndexComponent-将<router-outlet></router-outlet>放入html模板中。

以这种方式重组ResourceRoute:

const ResourceRouters: Routes = [
  {
    path: '',
    component: ResourceIndexComponent,
    children: [
      { path: '', pathMatch: 'full', component: ResourcePageComponent, canActivate: [AuthGuard] },
      { path: 'detail/:hulpbronId', component: ResourceDetailComponent, canActivate: [AuthGuard] },
    ],
  },
];