1
votes

Actually i am facing problem while establishing lazy loading in my app. I am using angular 6. Here is scenario-

In my app-routing.module.ts i have following routes-

const appRoutes: Routes = [

  {
    path: '',
    redirectTo: 'dashboard', pathMatch: 'full'
  },
  {
    path:'home',
    loadChildren: './main/home/home.module#HomeModule'
  }

  { path: '**', redirectTo: '/404' }
];

In my home.module.ts i have this routes-

const routes: Routes = [

  {
    path: '',
    component: HomeComponent
  },
  {
    path:'list',
    component: ListComponent
  }

];

Now want to navigate just like below-

  1. /home---> HomeComponent
  2. /list---> ListComponent

I can navigate to HomeComponent but can't navigate to ListComponent .can anyone help me how can i achieve this. Thank you

1
Can you share your app.module and home.module configurationBozhinovski
kindly can you be specific about which configuration? Actually i want to know how should i setup the route to access as 'localhost:4200/list'Shubhasish Nissan

1 Answers

1
votes

In order to access to list lazy loaded route the only way is through home route aka (localhost:4200/home/list)

const appRoutes: Routes = [

  {
    path: '',
    redirectTo: 'dashboard', pathMatch: 'full'
  },
  {
    path:'home',
    loadChildren: './main/home/home.module#HomeModule'
  },

  { path: '**', redirectTo: '/404' }
];

const routes: Routes = [

  {
    path: '',
    component: HomeComponent
  },
  {
    path:'list',
    component: ListComponent
  }

];

According to code that you provided, all the components that come under the home module will start with route prefix home. After starting the application you can access sign-in component using:

http//:localhost:4200/home/list