2017-05-26 58 views
1

试图创建Angular2一个简单的路由:Angular2 - 路由错误 - 类型 '串' 不分配键入 '<any>类型'

ERROR在 C:/项目/游戏化/ src目录/程序/应用程序。 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 ]})` 

回答

2

删除“,请尝试:

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

谢谢@汪史蒂文。它现在有效。 –

相关问题