Assertion error with empty route in Angular 9

Viewed 7870

I have following router configuration in my module:

const publicRoutes: Routes = [
  {
    path: 'public',
    component: PublicComponent,
    children: [
      {path: 'sign', component: SignComponent},
      {path: '', redirectTo: '/public/sign', pathMatch: 'full'},
      {path: '**', redirectTo: 'sign'},
    ]
  },
];

But when I navigate to only /public I am not redirected, but I get ERROR Error: ASSERTION ERROR: Type passed in is not ComponentType, it does not have 'ɵcmp' property. Can you bring a bit of light to my life please? I am horribly lost.

2 Answers

When this happened to me, the issue was that one of my routes was directing to a non-component class (with a similar name to the component class I wanted to direct to, I just fat-fingered the import). Posting this here hoping it helps someone else if you face this as I scratched my head for a while on a pretty simple fix.

const publicRoutes: Routes = [
  {
    path: 'public',
    component: PublicComponent,
    children: [
      {path: '', redirectTo: 'sign', pathMatch: 'full'},
      {path: 'sign', component: SignComponent},
      {path: '**', redirectTo: 'sign'}
    ]
  },
];
Related