2

I got two modules in my application one is the app.module and another one is user.module which gets lazy-loaded. On the app.module I got a sign-in component, sign-up component and main component. The main.component is the component consisting of a navbar and a sidebar. I want every component inside user.module to load inside the main.component. But I'm getting error in console Error: Cannot match any routes. URL Segment: 'user/home'.

enter image description here

app.routing

import { MainComponent } from './main/main.component';
import { SignInComponent } from './sign-in/sign-in.component';
import { SignUpComponent } from './sign-up/sign-up.component';

const routes: Routes = [

      { path: 'sign-in', component: SignInComponent, pathMatch: 'full' },
      { path: '', redirectTo: 'sign-in', pathMatch: 'full' },
      { path: 'sign-up', component: SignUpComponent }
      {
        path: '',
        component: MainComponent,
        children: [
          {
            path: 'user',
            loadChildren: () => import('./user/user.module').then(m => m.UserModule)
          },
    
        ]
    
      },
      /* { path: '500', component: Error500Component },
      { path: '**', component: Error404Component }, */
    ];
    
    @NgModule({
      imports: [RouterModule.forRoot(routes)],
      exports: [RouterModule]
    })
    export class AppRoutingModule { }

user.routing

import { HomeComponent } from './home/home.component';
import { Routes, RouterModule } from '@angular/router';
import { FriendsComponent } from './friends/friends.component';

    const routes: Routes = [
  {
    path: '',
    children: [
      { path: 'home', component: HomeComponent },
      { path: 'friends', component: FriendsComponent }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class UserRoutingModule { }
surjendu_dey
  • 578
  • 2
  • 11
  • 28

2 Answers2

0

You should import and export the UserRoutingModule in UserModule.

@NgModule({
  declarations: [..],
  imports: [UserRoutingModule],
  exports: [UserRoutingModule],
  providers: [..]
})
export class UserModule {}
Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91
0

everything looks ok, have you specified router-outlet in your main.component.html ?

<router-outlet></router-outlet>
Tony
  • 894
  • 4
  • 19