Good day folks,
I am having this issue in my Angular 2 application upon server startup (npm start
).
I redirect the base route or base path to
Edit: Since Angular 8, the way to lazy load modules is using dynamic imports such as:
export const appRoutes:Routes = [
{ path: 'user', loadChildren: () => import('path-to-module').then(m => m.UserModule)},
{ path: '', redirectTo: 'user', pathMatch: 'full'}
]
The accepted answer is not the correct way to implement lazyLoading at all. This should be the routing mechanism:
app.routes.ts
export const appRoutes:Routes = [
{ path: 'user', loadChildren: 'user/user.module#UserModule'},
{ path: '', redirectTo: 'user', pathMatch: 'full'}
]
user.routes.ts
export const userRoutes = [
{
path: '',
children: [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{
path: 'login',
component: LoginComponent
}]
} ]
ibenjelloun's answer is correct. Since you mentioned somehow it doesn't seem to work for you, I have given an alternative way with child routes.