I have a router outlet in the AppComponent which loads child components fine. One of the child component has multiple child components and I want to load all child components into the parent router-outlet like below
AppComponent <router-outlet> (This loads all child including products)
Customers (component)
Pricing (component)
Products (component) <router-outlet name="products"> (This should load child products)
TypeProduct1 (Component)
TypeProduct2 (Component)
But all my child products are loaded in the main router-outlet e.g. when I type the url
http://localhost:4200/products/typeproduct1 - it loads the TypeProduct1 component successfully but in the main router outlet and not the product router outlet.
I am lazily loading Products module in the route. Could that be the issue?
EDIT:
The routes looks like this:
AppRoutingModule:
const routes:Route = [
{ path: 'customers', loadChildren:'/path/to/customers/module' },
{ path: 'pricing', loadChildren:'/path/to/pricing/module' }
{ path: 'products', loadChildren: 'path/to/products/module' }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, useHash: true })],
exports: [RouterModule],
declarations: [NotFoundComponent]
})
ProductRoutingModule looks like this:
const routes: Routes = [
{ path: '', component: ProductsComponent },
{ path: 'type1', loadChildren: 'path/to/Type1product/module' },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
All components load in the top level router outlet. I expected the type1 module to load in the products router outlet.
name
attribute and just use nested (also called child) routes. – DeborahK