gpt4 book ai didi

javascript - Angular,在页面的哪个位置放置路由器导出

转载 作者:行者123 更新时间:2023-12-02 23:08:34 25 4
gpt4 key购买 nike

我有一个 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>

谢谢

这样子页面才能正确显示

最佳答案

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

创建一个新组件ResourceIndexComponent - 把<router-outlet></router-outlet>进入那里的 html 模板。

以这种方式重组资源路由:

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

关于javascript - Angular,在页面的哪个位置放置路由器导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57478670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com