尝试在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>
答案 0 :(得分:0)
你可以通过改变你的HomeComponent
来解决这个问题。
它应该从Type
延伸@angular/core
。并且不要忘记super
方法!
类似的东西:
import { Component, Type } from '@angular/core';
@Component({...})
export class HomeComponent extends Type {
constructor() {
super();
}
...
}