Angular2 - 路由错误 - 类型'string'不能分配给'Type <any>'

时间:2017-05-26 07:42:48

标签: angular-ui-router angular2-routing typescript2.0

尝试在Angular2中创建一个简单的路由:

错误 C:/projects/gamefication/src/app/app.routing.ts(8,7):

Type '({ path: string; redirectTo: string; pathMatch: string; } | 
{ path: string; component: string; })[]' 
is not assignable to type 'Route[]'.

Type '{ path: string; redirectTo: string; pathMatch: string; } | 

{ path: string; component: string; }' is not assignable to type 'Route'.
Type '{ path: string; component: string; }' is not assignable to type 'Route'.
  Types of property 'component' are incompatible.
    Type 'string' is not assignable to type 'Type<any>'

app.routing.ts如下:

const routes: Routes = [
{ path: '', redirectTo:'/login', pathMatch: 'full' },
{ path: 'explorer', component:'ExplorerQuizComponent' },
{ path:'login', component: 'LoginComponent'}];

@NgModule({imports: [ RouterModule.forRoot(routes) ], exports: [ RouterModule ]})`

1 个答案:

答案 0 :(得分:3)

删除&#39; ,请尝试:

const routes: Routes = [
{ path: '', redirectTo:'/login', pathMatch: 'full' },
{ path: 'explorer', component:ExplorerQuizComponent },
{ path:'login', component: LoginComponent}];