2016-10-17 4 views
3

角2で初めてルーティング設定しようとする(ルータ3.0.0)引数タイプ{パス:文字列、コンポーネントHomeComponentは} []パラメータ型ルートに割り当てない

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 { } 

Iを得ますエラー:

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> 
+0

'home.component.ts' –

+1

home.component.ts''からすべてのコードを追加してくださいのコードを表示してください。 'HomeComponent'は' @ Component'デコレータを持つクラスでなければなりません – yurzui

答えて

0

あなたのHomeComponent少し変更することで、この問題を解決することができます。 Type@angular/coreから拡張する必要があります。そして、super方法を忘れないでください!

そのような何か:

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

@Component({...}) 
export class HomeComponent extends Type { 
    constructor() { 
    super(); 
    } 
    ... 
} 
関連する問題