首页 > 解决方案 > 路由错误 - 类型“字符串”不可分配给类型“类型”'

问题描述

无法解决此问题,每当我尝试使用此路由方法时,它都会显示错误,例如

输入'{路径:字符串;组件:趋势组件的类型;}' 不可分配给类型 'Route'。对象字面量只能指定已知属性,并且“路径”类型中不存在“路径”。

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

标签: angularangular-routing

解决方案


将 'Route[]' 更改为 'Routes','Routes' 已经是一个对象类型数组。
'Routes' 应该以这种方式导入: import { Routes } from '@angular/router'。


推荐阅读