当前位置: 首页 > 知识库问答 >
问题:

角度 14 路径匹配类型“字符串”不可分配给类型“完整”|“前缀”' 错误

蓝侯林
2023-03-14

刚升级到Angular 14,出现错误:

Types of property 'pathMatch' are incompatible.
        Type 'string' is not assignable to type '"full" | "prefix"'.

呼叫发件人:

import { Routes as routes } from './routes';
@NgModule({
  imports: [
    RouterModule.forChild(routes)
    ]...})

路线是

export const Routes = [
  {
    path: '',
    redirectTo: '/signup',
    pathMatch: 'full'
  }]

整件事在Angular 10上运行得很好。有什么想法吗?

共有1个答案

扶杜吟
2023-03-14

您可以创建一个类型并对其进行强制转换:

type PathMatch = "full" | "prefix" | undefined;

const routes = [
  {
    path: 'achievements',
    component: AchievementOverviewComponent,
    pathMatch: 'full' as PathMatch
  }
]

相关答案中的详细信息:打字稿类型“字符串”不可分配给类型。

 类似资料: