参数类型路径的参数类型{path:string,component HomeComponent} []不可分配

时间:2016-10-17 14:01:25

标签: angular

尝试在Angular 2(路由器3.0.0)

上首次设置路由
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule} from '@angular/router';
import { AppComponent } from './app.component';
import { BoardComponent } from './board/board.component';
import { HomeComponent } from './home/home.component';

@NgModule({
  declarations: [
    AppComponent,
    BoardComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot([
        { path: '', component: HomeComponent }
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我收到错误:

Argument type {path: string, component HomeComponent}[] is not assignable to parameter type Routes

不确定这里发生了什么,因为我几乎跟着文档关注了这封信:https://angular.io/docs/ts/latest/guide/router.html

修改:home.component.ts

<p>Home works!</p>

1 个答案:

答案 0 :(得分:0)

你可以通过改变你的HomeComponent来解决这个问题。 它应该从Type延伸@angular/core。并且不要忘记super方法!

类似的东西:

import { Component, Type } from '@angular/core'; 

@Component({...}) 
export class HomeComponent extends Type { 
  constructor() { 
    super(); 
  } 
  ... 
}