1

我正在为 Journey Entity 创建 CRUD,并在 Angular 中创建了两个组件。

  • 列表
  • 编辑

该列表从服务中获取所有旅程并显示它们。编辑有一个表单,如果它传递了一个旅程 ID,它将添加一个新的旅程或编辑一个旅程。

我有很多实体,并且正在使用带有 url 参数的路由来实现这一点:

     <a mat-button [routerLink]="['/journey-edit', journey.id]">{{journey.name}}</a>

我现在发现了子组件,我可以在其中将旅程从列表传递到编辑,然后隐藏列表:

    <app-journey-view *ngIf="currentJourney" [journey]="currentJourney"></app-journey-view>

现在我被困住了。我该走哪条路?

  • 我需要路由吗
  • 我可以将路由与子组件混合使用吗
  • 身份验证在我的路线上。这是否适用于子组件:

     {
     path: 'journey-list',
     component: JourneyListComponent,
     canActivate: [AuthGuardService]
     },
    

这个应用程序将有许多实体,大多数实体将通过关系数据库链接。

4

1 回答 1

1

只需使用路由。如果隐藏列表,则无法从 url 获取特定项目。

{ 
  path: 'journey',
  children:[
    { path: 'journey-list', component: JourneyListComponent},
    { path: ':id', component: JourneyDetailComponent},
    { path: 'edit/:id', component: JourneyEditComponent}
  ]
}

于 2018-08-22T18:04:56.747 回答