【问题标题】:Can we have same path with different routing component - Angular Routing我们可以使用不同的路由组件拥有相同的路径吗 - Angular Routing
【发布时间】:2019-02-08 09:19:50
【问题描述】:

我有一个component,它渲染了一些子路由,但布局不同 - 我们可以为两种布局使用相同的路径名,如下所示

{
    path: '',
    component: LandingComponent,
    children: [
      { path: '', component: LandingpageComponent },
      { path: 'landingpage', component: LandingpageComponent },
    ]
  },
  {
    path: '',
    component: DashboardComponent,
    children: [
      { path: 'patients', component: PatientsComponent },
      { path: 'endrolPatient', component: ProfileComponent },
      { path: 'endrolPatient/:id', component: ProfileComponent },

    ]
  }

在上面的示例中,路径名称是相同的 - 当我运行应用程序时,我可以看到输出 - 角度如何处理这种关闭路由。

【问题讨论】:

    标签: angular angular-routing


    【解决方案1】:

    是的,你可以!

    基本上,根据 Angular 路由器结构,您可以为同一个组件拥有多个路由器路径。

    假设您想使用带有两个链接的组件 A,如下所示 -

    abc.com/first
    abc.com/second
    

    在这种情况下,您可以使用相同的组件。

    【讨论】:

    • 路径名可以相同吗?在我的情况下,我有两个名称为空的路径 - 但是角度选择正确的孩子路由组本身如何?
    • 是的,路径名可以相同但处于同一级别,但为什么有人这样做。没有任何意义。在您的情况下,存在父母和孩子的概念。此外,您还必须在父路线中拥有出口,以便它将第一个空/默认子项显示为您的路线。
    猜你喜欢
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    相关资源
    最近更新 更多