angular - 在 Angular 2 中用 subview 替换父 View 路由器 View

标签 angular angular2-routing

我有如下代码片段中给出的路由配置 -

export const projectRoutes: Routes = [
  {
    path: 'projects', component: ProjectComponent, canActivate: [AuthGuard]
  },
  {
    path: 'project/:id', component: ProjectDetailsComponent, canActivateChild: [AuthGuard],
    children: [
      { path : 'adduser', component: AddMemberComponent, canActivate: [AuthGuard]}
    ]
  }
]

这是模块定义(顺便说一句,这不是根模块,这是一个子/功能模块)-

//imports are removed to maintain sanity

@NgModule({
  imports: [
    CommonModule,
    ProjectRoutingModule
  ],
  declarations: [routableComponents],
  providers: [ProjectService]
})
export class ProjectModule { }

项目详细信息 HTML 是 -

<div *ngIf="project" class="row justify-content-md-center">
   <!-- project details here -->
</div>
<router-outlet>
</router-outlet>

现在我想在用户转到这条路线时显示添加用户表单 - /project/{id}/adduser.

由于路由 adduserproject/:id 的子级,因此它加载到该 HTML 下的 router-outlet 中。但是,我想替换相同的 View 而不是在已经呈现的 HTML 下显示它。就像图片中给出的一样 -

Existing setup

我想达到的目标-

enter image description here

有什么办法可以实现吗?

最佳答案

您可以考虑从子状态中删除 adduser:

export const projectRoutes: Routes = [
  {
    path: 'projects', component: ProjectComponent, canActivate: [AuthGuard]
  },
  {
    path: 'project/:id', component: ProjectDetailsComponent, canActivateChild: [AuthGuard]},

      { path : 'projects/:id/adduser', component: AddMemberComponent, canActivate: [AuthGuard]}

  }
]

关于angular - 在 Angular 2 中用 subview 替换父 View 路由器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41671341/

相关文章:

Angular 4 延迟加载和路由不起作用

javascript - 如何在 Angular 2 中重新加载组件的内容?

javascript - Mobile Firefox 上的 Angular 4 应用程序呈现问题

angular - Angular 中不同模块的数组的类型是什么?

Angular 2/4 : How to check length of input's value using directive?

angular - TypeError : this. _platformStrategy.getBaseHref 不是函数

angular - 来自同一惰性路由的多个组件不起作用

Angular6 ngrx : Cannot read property 'ids' of undefined

angular - Firebase实时数据库中有 "Multi-Path Push"这样的东西吗?

angular - 为什么 Angular2 中必须使用 routerLink?