0
這是我app.module.ts文件錯誤路線上的陣列上angular2路由
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 { }
我對路線數組聲明一個錯誤,說路線的內容是不能分配給一個路由陣列。這是完整的錯誤消息,它顯示
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'在使用'pathMatch'。 例如:https://angular.io/docs/ts/latest/guide/router.html#!#basics-config – sandrooco
我已經爲'{path:'',redirectTo:'home',pathMatch:'全'}'與結果相同 – AFS
這就是你的問題@Sandrooco – AFS