【问题标题】:Navigation to child routes gives error "cannot match any routes"导航到子路线给出错误“无法匹配任何路线”
【发布时间】:2018-02-10 04:05:05
【问题描述】:

在我的路由中,创建了子组件,我可以在路由器插座中看到默认子路由。但是当导航到其他子路由时,显示错误“无法匹配任何路由”。

routing.ts

const appRoutes: Routes = [
{
  path: '',
  component: HomeComponent
},
{
    path: 'dashboard',
    pathMatch: 'full',
    component: DashboardComponent,
    canActivate: [AuthGuard],
    children: [
      {
        path: '',
        pathMatch: 'full',
        component: DashboardhomeComponent
      } ,
       {
        path: 'profile',
         pathMatch: 'full',
        component: ProfileComponent
      } 
    ] 
  },
  {
    path: 'login',
    component: LoginComponent
  },

];

dashboard.ts

goto() {
  this.router.navigate(['dashboard/profile']);
}

【问题讨论】:

    标签: angular angular2-routing


    【解决方案1】:

    试试

    this.router.navigate(['/dashboard/profile']);
    

    并将您的路线更改为,

    const appRoutes: Routes = [
      {
        path: '',
        component: HomeComponent
      },
      {
        path: 'dashboardhome',
        component: DashboardhomeComponent,
        canActivate: [AuthGuard],
        children: [
          { path: 'profile', component: ProfileComponent }           
    
        ]
      },
      {
        path: 'login',
        component: LoginComponent
      },
    
    ];
    

    【讨论】:

    • 显示“无法匹配任何路由。URL Segment: 'dashboard/profile'”同样的错误。
    • @Sajeetharam U 可以在这里看到完整的代码drive.google.com/open?id=1E2jtFuU_dU6102v-r2ePZ8fesciTKpCV
    • @Sajeetharan 您建议的路线更改可能最终导致无限循环调用路线“仪表板”,他将无法转到“仪表板主页组件”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 2020-06-22
    • 2019-05-01
    • 2017-01-08
    • 2019-06-30
    • 1970-01-01
    相关资源
    最近更新 更多