Search code examples
angularangular-routing

routing error - Type 'string' is not assignable to type 'Type<any>'


Unable to resolve this problem, whenever I tried to use this routing method it showing error like

Type '{ path: string; component: typeof TrendsComponent; }' is not assignable to type 'Route'. Object literal may only specify known properties, and 'path' does not exist in type 'Route'.

export const MODULE_ROUTES: Route[] = [
  { path: 'trends', component: TrendsComponent },
  { path: 'customtrend', component: CustomtrendComponent },
  { path: '**', redirectTo: 'trends', pathMatch: 'full' }
];

Solution

  • I guess that you are using Route from angular/compiler/src/core (import { Route } from '@angular/compiler/src/core';), it's not correct.

    You can use Route[] as well, but make sure that Route is imported like this import { Route } from '@angular/router';

    Happy coding!