导航到子路线会出错 "cannot match any routes"

Navigation to child routes gives error "cannot match any routes"

在我的路由中,创建了子组件,当导航到其他子路由时,我可以在路由器 outlet.But 中看到默认子路由,显示错误 "cannot match any routes"。

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

尝试

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

];