这是我的app.module.ts文件
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 { }
我在routes数组声明中有一个错误,说路由的内容不能分配给Routes数组。这是它显示的完整错误消息
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 :(得分:0)
redirectTo
,您必须使用pathMatch
。component
不应该是字符串,而是组件本身。