I am trying to lazy load the module with angular 2.
I have two modules
- AppModule (main module)
- ProductModule (lazily loaded module)
AppModule.ts
@NgModule({
imports: [
BrowserModule,
HttpModule,
RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: 'products', loadChildren:'app/products/product.module#ProductModule'}
])
],
declarations: [AppComponent,
WelcomeComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
Here I have two routes one is default route that is blank and one is welcome screen in AppModule. It contains one more route products to initiate lazy loading of modules and relevant component that is ProductModule.
and now ProductModule looks like this:
@NgModule({
declarations: [
ProductListComponent,
ProductDetailComponent,
ProductFilterPipe
],
imports: [
SharedModule,
RouterModule.forChild([
{ path: '', component: ProductListComponent },
{ path: 'product/:id', component: ProductDetailComponent, pathMatch:'full'}
])
],
providers: [
ProductService,
ProductDetailGuard
]
})
export class ProductModule {
}
as you can see my ProductModule is having empty routes (for listing product) and one route with product/id which shows product detail.
Now for the first route in ProductModule having ProductListComponent is activated when I navigated to http://localhost:3000/products which is OK but for the second route which is having ProductDetailComponent is activated when I navigated to http://localhost:3000/products/product/1.
Now for the detail screen url I do not wanted to have products in the url.
I have already tried specifying { path: 'products', component: ProductListComponent } route. But unluckily it doesn't worked.
Please explain me why it needs the products in the detail screen URL and how can I make it activated on http://localhost:3000/product/1 URL?