javascript - Angular-如何使用重复组件路由父/子?
问题描述
我正在尝试找出最简洁的方式来设置我的 Angular 路由。
我有一条父路线,在孩提时代,我想多次重复相同的组件(所有位置的列表)。每个位置(子)组件的出现看起来都是一样的,只是需要传入不同的数据。(我将使用 *ngFor 执行此操作)。
到目前为止,这是我的想法:
<router-outlet>//for the parent
<router-outlet name="aux">
<ul *ngFor="let location in service.locations"
</router-outlet>
//where I list out all the locations^
</router-outlet>
在我的 app-routing.module.ts 文件中:
const routes: Routes = [
{ path: 'main', component: MainComponent }, //lists all locations
{ path: 'locations/:id', component: LocationsComponent }, //view 1
location
{ path: '', pathMatch: 'full', redirectTo: '/main},
];
(我想让父母和孩子都出现在初始加载中。我应该修改它吗?^)
现在这是我不太了解的部分,我需要设置我的路由配置。这很近吗?它是否也在我的 app-routing.module.ts 文件中?
@RouteConfig([
{path:'/', name: 'MainPath', component: MainComponent,
useAsDefault: true},
{aux:'/auxRoute', name: 'AuxPath', component: SecondComponent}
])
谢谢!如果您需要澄清,请告诉我。
解决方案
推荐阅读
- solr - SOLR ,将函数应用于查询中的参数
- google-app-engine - 503 谷歌应用引擎中的服务不可用
- scala - 如何将 for-yield 循环与 if/else 构造相结合
- php - Ion Auth in_group() - 多个组(按 id)
- javascript - 如何在 JavaScript 中将此日期字符串转换为毫秒
- c++ - 如何在一个 qt qml 窗口中运行和显示 4 个可执行文件?
- javascript - 当条件为真时,cancelAnimationFrame() 不起作用 - JS Canvas
- rest - 如何从 SOAP (JIRA 6) 迁移到 REST Api (JIRA 7)
- c# - c#Excel相对FormulaR1C1不起作用
- dart - 如何在 Dart 或 Flutter 中将日期转换为儒略日期?