angularpathdefaultrouteroutlet

Angular default router outlet


I have user module and i'm trying to load a default router outlet. i want to load UserHomeComponent when the path is /user but it's not working. if i add a path instead of keeping it empty it works fine. This is my user routing module:

const routes:Routes = [
    {path: 'user' ,  component: UserComponent , children:[
        {path: '' , component: UserHomeComponent},
        {path: 'new-request' , component: NewRequestComponent},
        {path: 'checkout' , component: CheckoutComponent},
        {path: 'edit-info' , component: UserEditInfoComponent},
        {path: 'requests', component: UserRequestsComponent},
        {path: 'change-password' , component: UserChangePasswordComponent},
        {path: 'delete-account' , component: DeleteAccountComponent}
    ]}
]

And this is my app routing module:

const appRoutes:Routes = [
    {path: '' , redirectTo: 'login' , pathMatch: 'full'},
    {path: 'login' , component: LoginComponent },
    {path: 'signup' , component: SignupComponent},
    {path: 'user' , loadChildren: () => import('./user/user.module').then(m => m.userModule)},];

Solution

  • to load a UserHomeComponent, change this

    {path: 'user' ,  component: UserComponent , children:[
    

    by

    {path: '' ,  component: UserComponent , children:[