S
S
Sergey2017-10-18 20:43:00
Angular
Sergey, 2017-10-18 20:43:00

Routes loads angular 2 parent module, how to fix?

There are routes

const Routes: Routes = [
  {path: '', loadChildren: './entry-module/entry.module#EntryModule'},
  {path: 'auto', loadChildren: './auto-module/auto.module#AutoModule'},
  {path: 'avia', loadChildren: './avia-module/avia.module#AviaModule'},
];

The EntryModule is always loaded. How to make it lazily loaded only here: ''

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sasha Novik, 2017-10-19
@Sergamers

Place it at the end of the list:

const Routes: Routes = [
  {path: 'auto', loadChildren: './auto-module/auto.module#AutoModule'},
  {path: 'avia', loadChildren: './avia-module/avia.module#AviaModule'},
  {path: '', loadChildren: './entry-module/entry.module#EntryModule'},
];

But keep in mind that if there is a wildcard processing (for example, for a 404 page), then it will still load it. Because the wildcard will be lower, and the router must check the routes inside the module.
An alternative option is to redirect with an empty route, like this:
{
    path: '',
    pathMatch: 'full',
    redirectTo: 'entry',
  },
  {
    path: 'entry',
    loadChildren: 'entry-module/entry.module#EntryModule',
  },
  ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question