2017-04-13 40 views
0

这是我app.module.ts文件错误路线上的阵列上angular2路由

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { RouterModule, Routes} from '@angular/router'; 

import { AppComponent } from './app.component'; 
import { CronoComponent } from './crono/crono.component'; 
import { ClockFactory } from './classes/clockFactory'; 
import { PruebaComponent } from './prueba/prueba.component'; 

const routes: Routes = [ 
    { path:'', redirectTo:'home'}, 
    { path:'crono', component:'CronoComponent' }, 
    { path:'prueba', component:'PruebaComponent' } 
]; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    CronoComponent, 
    PruebaComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    RouterModule.forRoot(routes) 
    ], 
    providers: [ClockFactory], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

我对路线数组声明一个错误,说路线的内容是不能分配给一个路由阵列。这是完整的错误消息,它显示

Type '({ path: string; redirectTo: string; } | { path: string; component: string; })[]' is not assignable to type 'Route[]'. 
    Type '{ path: string; redirectTo: 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>' 
+0

你可以用'只有redirectTo'在使用'pathMatch'。 例如:https://angular.io/docs/ts/latest/guide/router.html#!#basics-config – sandrooco

+0

我已经为'{path:'',redirectTo:'home',pathMatch:'全'}'与结果相同 – AFS

+0

这就是你的问题@Sandrooco – AFS

回答