Angular 角度2路由器导航未定义
每次单击链接并加载新组件时,都会引发以下错误 区域显示的行类似于responsiveheight.component.ts:111是错误的,其中没有http连接 在angular的早期版本中,这只发生在构建文件中,不在开发环境中,但在2.2之前,它也发生在开发模式下 我不知道问题是否与angular2路由器或angular cli有关 目前我将angular 2.3.1与angular一起使用-cli@1.0.0-beta.26 有什么想法吗 更新: 我的路线在那里,我在中间删除了几个相同的,用Fo.bar改变了一些域名。< /P>Angular 角度2路由器导航未定义,angular,angular2-routing,angular2-router3,Angular,Angular2 Routing,Angular2 Router3,每次单击链接并加载新组件时,都会引发以下错误 区域显示的行类似于responsiveheight.component.ts:111是错误的,其中没有http连接 在angular的早期版本中,这只发生在构建文件中,不在开发环境中,但在2.2之前,它也发生在开发模式下 我不知道问题是否与angular2路由器或angular cli有关 目前我将angular 2.3.1与angular一起使用-cli@1.0.0-beta.26 有什么想法吗 更新: 我的路线在那里,我在中间删除了几个相同的,
const routes: Routes = [
{
path: '',
component: Component1,
pathMatch: 'full'
},
{
path: 'foo/bar',
component: Component2
},
{
path: 'user/profile',
component: ProfileComponent
},
{
path: '404',
component: NotFoundComponent
},
{
path: '**',
redirectTo: '404',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class RoutingModule {
}
更新2:
aplicación工作正常,没有奇怪的行为。但是这个错误被抛出,我想修复它
更新3:
app.module:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ErrorModule,
HeaderModule,
HttpModule,
SharedModule,
RoutingModule,
UserModule
],
providers: [
{
provide: LOCALE_ID,
useValue: window.navigator.userLanguage || window.navigator.language
},
{provide: RequestOptions, useClass: DefaultRequestOptions},
{provide: ConnectionBackend, useClass: XHRBackend},
{provide: Http, useExisting: HttpInterceptor},
],
bootstrap: [AppComponent]
})
export class AppModule {
}
对于没有
子级的空路径路由
或重定向
,您需要路径匹配:'full'
:
{
path: '',
component: Component1,
pathMatch: 'full'
},
否则,路由器将继续查找子路由。组件声明缺失或导入路径错误
declarations: [
AppComponent,
Component1,
Component2
...
]
检查你的路径。供给
app.routes.ts:
const routes: Routes = [
{
path: '',
component: HeaderComponent
},
{
path: 'shared',
component: SharedComponent
},
{
path: '**',
redirectTo: '404'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class RoutingModule {
}
shared.module.ts与header.module.ts类似
@NgModule({
imports: [
CommonModule
],
declarations: [SharedComponent]
})
export class SharedModule { }
没有错误的路由。我发现了错误,
背景图像:css文件中的none
会导致该错误。@MKK路由器\u提供商
在6个多月前消失;-)RouterModule比@GünterZöchbauer更重要。请显示一些代码。@MMK它是@GünterZöchbauer happy:)好的,但不能解决问题。我在上面更改了,对吗?所有组件都在导入的模块中声明。也没有懒惰的路线。所以这不是问题所有组件都声明了,我们在哪里可以看到它?提供工作plunker或pastebin等。检查组件声明的路径。