尝试在Angular2中创建一个简单的路由:
错误 C:/projects/gamefication/src/app/app.routing.ts(8,7):
Type '({ path: string; redirectTo: string; pathMatch: string; } |
{ path: string; component: string; })[]'
is not assignable to type 'Route[]'.
Type '{ path: string; redirectTo: string; pathMatch: 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>'
app.routing.ts如下:
const routes: Routes = [
{ path: '', redirectTo:'/login', pathMatch: 'full' },
{ path: 'explorer', component:'ExplorerQuizComponent' },
{ path:'login', component: 'LoginComponent'}];
@NgModule({imports: [ RouterModule.forRoot(routes) ], exports: [ RouterModule ]})`
答案 0 :(得分:3)
删除&#39; ,请尝试:
const routes: Routes = [
{ path: '', redirectTo:'/login', pathMatch: 'full' },
{ path: 'explorer', component:ExplorerQuizComponent },
{ path:'login', component: LoginComponent}];