【问题标题】:How to configure child routes properly?Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'parent/child1如何正确配置子路由?错误:未捕获(承诺):错误:无法匹配任何路由。 URL 段:'父/子1
【发布时间】:2017-06-01 07:40:42
【问题描述】:

配置子路由后出现以下错误。

错误:未捕获(承诺中):错误:无法匹配任何路由。 URL 段:'parent/child1

app.routing.ts

{ path: 'home', component: homeComponent},
  { path: 'about', component: aboutComponent},
  { path: 'parent', component: parentComponent,
    children:[
    {
      path: '',
      redirectTo: '/parent/child1',
      pathMatch: 'full'
    },
    {
      path: 'child1',
      component: child1Component,
      outlet: 'subRouter'
    },
    {
      path: 'child2',
      component: child2Component,
      outlet: 'subRouter'
    }]
  },
{ path: '**', redirectTo: 'home', pathMatch: 'full' }

在我的 index.html 中,我有 <router-outlet></router-outlet>

在我的 parent.htm(parentComponent) 我有 <router-outlet name="subRouter"></router-outlet>

我错过了什么?为什么我收到这个错误?我该如何解决这个错误?

【问题讨论】:

    标签: javascript angularjs angular2-routing nested-routes


    【解决方案1】:

    parent 路由子 '' 路径重定向应更改为下面,并明确提及 outlet:component 值。

    redirectTo: '/child1(subRouter:child1)'
    

    因为/parent 将在您从子路由重定向时被隐式包含在内。

    【讨论】:

    • 进行此更改后,我遇到了与 URL Segment: 'child1' 相同的错误
    • 不。仍然得到同样的错误。指定出口和组件值后
    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 2022-11-10
    • 2018-09-21
    • 2019-10-14
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多