我试图建立路由首次上角4:Angular4:无法编译:参数类型{路径:串,组分HomeComponent} []是不能分配给参数类型路由
我app.module.ts代码:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { MembersComponent } from './members/members.component';
@NgModule({
declarations: [
AppComponent,
ProductComponent,
MembersComponent
],
imports: [
BrowserModule,
NgModule,
RouterModule.forRoot([
{
path: 'member',
component: 'MembersComponent'
},
{
path: 'product',
component: 'ProductComponent'
}
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我得到的错误:
Argument of type '{ path: string; component: string; }[]' is not assignable to parameter of 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'.
请删除 '' 行情只是添加MembersComponent在组件属性 –
组件用作字符串,但它应该是一种组件。你必须记住你正在使用打字稿,它理解类型。 –