【发布时间】:2017-03-04 23:17:14
【问题描述】:
我正在创建一个带有一些简单路由的 Angular 2 应用程序:
(main.module.ts)
import { routes } from './main.routes';
/* Other imports */
@NgModule({
imports: [
HomeModule,
TestModule,
RouterModule.forRoot(routes) // imported from file below
],
declarations: [MainComponent, SidebarComponent],
exports: [MainComponent, SidebarComponent]
})
(main.routes.ts)
import { Route } from '@angular/router';
/* Other imports */
export const routes = [
{
path: '',
component: MainComponent,
children: [
{ path: 'home', component: HomeComponent },
{ path: 'test', component: TestComponent }
]
}
];
当我键入 npm start 时,应用程序运行良好,但我的 IntelliJ IDE 在RouterModule.forRoot(routes) 行显示错误
参数类型 {path: string, component: MainComponent, children: {path: string, component: HomeComponent}|{path: string, component: TestComponent}[]}[] 不能分配给参数 Routes
我也试过了:
export const routes: Routes = ] 而不是 export const routes = [
经过搜索,我无法找到没有错误地实施它的原因或替代方案。
【问题讨论】:
-
当你使用
export const routes: Routes时,如果你双击类型Routes,它应该带你到类型定义。定义是什么样的,它在哪个文件中?
标签: angular intellij-idea