导航到子路由会出现错误“无法匹配任何路由”

时间:2018-02-10 04:05:05

标签: angular angular2-routing

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

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']);
}

1 个答案:

答案 0 :(得分:2)

尝试

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
  },

];