this is my app.module.ts file
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 { }
I have an error on the routes array declaration ,says that the content of routes is not assignable to a Routes array.This is the complete error message that it shows
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>'
redirectTo
, you have to use pathMatch
. component
s shouldn't be strings but the component itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.