I am trying to achieve lazy loading in my Angular app. Here are my routes:
app-routing.module.ts
const routes: Routes = [
{
path: '',
loadChildren: './customer/customer.module#CustomerModule',
pathMatch: 'full'
}
];
and in module:
imports: [RouterModule.forRoot(routes)],
customer-routing.module.ts
export const routes: Routes = [
{ path: '', component: ComparePageComponent },
{ path: 'funds', component: FundSelectionComponent },
{ path: ':service', component: ComparePageComponent },
{ path: '**', component: PageNotFoundComponent },
];
and in module :
imports: [
RouterModule.forChild(routes)
],
Now, I have a logic that will load the /profile
page when there are no path params i.e. when the url is '' (this._router.navigate(['', 'profile'])
) for which I have already defined a path in my customer module { path: ':service', component: ComparePageComponent }
But, when the app runs, it results in the following error:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'profile' Error: Cannot match any routes. URL Segment: 'profile' at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirect
Not really sure where I am going wrong.