angular - 如何让孙子在 Angular 6 中使用祖 parent <router-outlet>

标签 angular routes angular6 parent-child

我有一个我在这次堆栈 Blitz 中寻找的示例: https://angular-czk5vj.stackblitz.io/

基本上我想做的是让孙子路由在祖级路由器导出中渲染。

即 路线: 雇员 ---> Emp 报告 ------>报告详细信息

查看

当单击第一列中的姓名时,它会路由到第二列中的员工报告。单击第二列中的报告时,会在第三列中显示报告详细信息。

我觉得我需要在路由中完成此操作的原因是我希望能够通过 url (employees/11/reportdetail/2) 发送准确的报告,以便应用程序可以在该报告上打开。我愿意接受另一种方法来实现这一目标。

enter image description here

最佳答案

您的实现中存在一些命名约定的严重问题。所以我决定创建自己的。它没有模块的延迟加载,但这是您已经知道并且可以实现的。

回到您的要求,您可以将每个级别实现为到上一个级别的子路由。因此,作为父组件的每个组件模板中都会有一个 router-outlet 标记。

所以你的routes配置可以看起来像这样:

const routes: Routes = [
  { path: 'employees', component: EmployeesComponent, children: [
    { path: ':id', component: ReportsComponent, children: [
      { path: 'detail/:repId', component: DetailsComponent },
      { path: '**', component: PlaceholderComponent }
    ] },
    { path: '**', component: PlaceholderComponent }
  ] },
  { path: '**', redirectTo: '/employees', pathMatch: 'full' }
];

请注意,这里我还有一个 PlaceholderComponent,如果需要从列表中选择一个项目,它将显示。

我使用 Bootstraps Grids 来管理三列内容的分布。这就是您所需要的。


这是一个Working Sample StackBlitz供您引用。

关于angular - 如何让孙子在 Angular 6 中使用祖 parent <router-outlet>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53623040/

相关文章:

components - Angular 2如何将变量从父组件传递到路由器导出

javascript - 无法以 Angular 找到 CSS

angular - 代理配置在 Angular 6 中不起作用

c# - Sitecore、自定义 MVC Controller 和路由

flutter - 在Flutter中具有路由的持久性BottomNavigationBar

angular - 如何在 Angular 2+ 应用程序中使用 Azure 媒体服务

node.js - 当用户点击 pwa、Angular 6 和 Node.JS 中的 web-push 中的通知时路由到 url

angular - 错误: both async and sync fetching of the wasm failed

angular - 如何使用 Angular 7覆盖 ionic 4中的 ionic 后退按钮 Action

javascript - react-router-dom - 将参数添加到索引 url 但接受页面