I'm developing a client for a rest API using Angular 5 and a lazy loading architecture. I have the following routes in the AppModule
that are imported using the RouterModule
forRoot()
method:
const routes: Routes = [
{
path: '',
loadChildren: 'app/home/home.module#HomeModule',
},
{
path: 'login',
loadChildren: 'app/login/login.module#LoginModule',
},
{
path: 'register',
loadChildren: 'app/register/register.module#RegisterModule',
},
{
path: 'forgot-password',
loadChildren: 'app/forgot-password/forgot-password.module#ForgotPasswordModule',
},
{
path: 'events',
loadChildren: 'app/events/events.module#EventsModule',
}
];
And then for HomeModule
, LoginModule
, RegisterModule
and PasswordModule
I only have this route for each one:
const routes: Routes = [
{
path: '',
component: ...
}
];
Each of them is imported using the RouterModule
forChild()
method. And for the EventsModule
the routes are these:
const routes: Routes = [
{
path: '',
component: EventSearchResultsComponent,
},
{
path: 'new',
component: NewEventComponent,
},
{
path: ':id',
component: EventDetailsComponent
}
];
The problem I'm facing is that every route in my application is loading the EventDetailsComponent
except for the root route, that is loading correctly the HomeComponent
. But if I delete the :id
route from the EventsModule
all is working fine! Why it stops working when I add the last route?
PS: To navigate to each of these routes I'm only using the routerLink directive like this routerLink="/register">
.