My application is structured as follows:
app.module.ts
const routes: Routes = [
{ path: '', loadChildren: './modules/main/main.module#MainModule' },
];
@NgModule({
declarations: [
AppComponent,
],
imports: [
RouterModule.forRoot(routes),
],
providers: [
AuthService,
UtilService,
UserService
],
bootstrap: [AppComponent]
})
export class AppModule {
}
main.module.ts
@NgModule({
declarations: [
PressComponent,
LegalComponent
],
providers: [
AuthService
],
imports: [
HomeModule,
MainRoutingModule,
]
})
export class MainModule {
}
main.routing.component.ts
const routes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AnonymousGuard] },
{ path: 'home', component: HomeComponent, canActivate: [AnonymousGuard] },
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MainRoutingModule implements OnInit {
constructor() { }
ngOnInit() {
RouterModule.forRoot(routes, { scrollPositionRestoration: 'enabled' });
}
}
When trying to access /home
it works fine, but accessing /
doesn't. How can I resolve this issue?