Angular 2 router Error: Invalid configuration of route 'undefined'
In my case, i forgot remove component from default route
{ path: '', redirectTo: '/home', component: MovieComponent, pathMatch: 'full' },
{ path: 'home', component: MovieComponent }
Just remove component: MovieComponent from first line
You need to provide the correct relative path for the HomeComponent import:
instead of this:
import {HomeComponent} from './';
do this:
import {HomeComponent} from './home.component';
app.routes.ts
import {provideRouter, RouterConfig} from '@angular/router';
import {HomeComponent} from './home.component'; // you need to provide correct relative path
const appRoutes:RouterConfig = [ //removed export
{ // removed square bracket
path: '',
redirectTo: '/home',
pathMatch: 'full'
},{
path: 'home',
component: HomeComponent
}
];
export const appRouterProviders = [
provideRouter(routes)
];
main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppComponent} from './app.component'; //please provide right path
import {appRouterProviders } from './app.routes'; // added
bootstrap(AppComponent, [appRouterProviders])
.catch(err => console.error(err));
For future readers:
This error will also show if the Component in question is not registered on the module, and can be quite confusing.