Search code examples
angularangular2-routingangular2-router3

Angular 2 router navigates undefined


Every time I click on a link and a new component is loaded, the following error is thrown.

enter image description here

The line that zone shows like responsive-height.component.ts:111 is wrong, there's no http connections in there.

In previous versions of angular, this only happens with built files, not in development environment, but up to 2.2, it happens in dev mode as well.

I don't know if the problem is related to angular2-router or angular-cli.

Currently I use angular 2.3.1 with [email protected].

Any idea?

UPDATE: My routes are there, I delete several in the middle that are the same, and change some domain names by foo bar.

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 {
}

UPDATE 2: The aplicación works properly, no weird behaviors. But this error is thrown and I want to fix it.

UPDATE 3:

The 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 {
}

Solution

  • I found the error, background-image: none in a css file causes that error.