错误

2017-07-03 29 views
0

我想设置为我的应用程序页面导航的路线,但得到以下错误:错误

ERROR in C:/my-app/src/app/router.component.ts (9,2): Type '({ Path: string; redirectTo: string; PathMatch: string; } | { Path: string; component: typeof Abo...' is not assignable to type 'Route[]'. Type '{ Path: string; redirectTo: string; PathMatch: string; } | { Path: string; component: typeof Abou...' is not assignable to type 'Route'.

代码:

export const router: Routes=[ 
    {Path:'', redirectTo:'about', PathMatch:'full'}, 
    {Path:'about', component:AboutComponent}, 
    {Path:'products', component:ProductsComponent}, 
]; 
+0

看这里的文档︰https://angular.io/api/router/Routes路径属性应该是小写? – robjam

+0

如果有任何答案对您有所帮助,您能否接受或者赞扬它?谢谢。 –

+0

谢谢你的帮助,我纠正了我的代码,并得到了预期的结果。这篇文章节省了我的时间。非常感谢你 –

回答

0

尝试没有大写:

export const router: Routes=[ 
    {path:'', redirectTo:'about', pathMatch:'full'}, 
    {path:'about', component: AboutComponent}, 
    {path:'products', component: ProductsComponent}, 

    ]; 
0

当您看到这些is not assignable to type 'X'异常时,这是因为对象字面值的结构不匹配分配结构(区分大小写)。

export interface Route { 
    path?: string; 
    pathMatch?: string; 
    matcher?: UrlMatcher; 
    component?: Type<any>; 
    redirectTo?: string; 
    outlet?: string; 
    canActivate?: any[]; 
    canActivateChild?: any[]; 
    canDeactivate?: any[]; 
    canLoad?: any[]; 
    data?: Data; 
    resolve?: ResolveData; 
    children?: Routes; 
    loadChildren?: LoadChildren; 
    runGuardsAndResolvers?: RunGuardsAndResolvers; 
} 

与在JavaScript中,pathpathMatch在驼峰定义的大多数属性:当我们检查路由接口,该变得清晰。

export const router: Routes = [ 
    {path:'', redirectTo:'about', pathMatch:'full'}, 
    {path:'about', component:AboutComponent}, 
    {path:'products', component:ProductsComponent} 
];