Search code examples
angularangular-routingangular-router

Angular route after adding param how we can add sub route


As an Example : 'www.xyz.com/#/indutry/1/subIndustry/2/subSubIndustry/3'

I need to follow this structure how I can ForRoot my Parent route file


Solution

  • You need two level nested child routing.

    Make sure every route has a unique name.

    Your route file.

    That basic example, it depends on your app which kind of data you want to show.

    const routes: Routes = [
      {path: '', redirectTo: 'home', pathMatch: 'full'},
      {path: 'home', component: HomeComponent},
      {
        path: 'indutry/:indutryId',
        component: IndutryComponent,
        children: [
          {path: '', redirectTo: 'subIndustryone', pathMatch: 'full'},
          {
            path: 'subIndustryone/:subindustryOneId', 
            component: SubIndustryOneComponent,
            children : [
              { path : '', redirectTo: 'subIndustrytwo', pathMatch : 'full' },
              { path : 'subIndustrytwo/:subindustryTwoId', component : SubIndustryTwoComponent },
            ]
          },
    
        ]
      },
      {path: '**', component: HomeComponent}
    ];
    

    Plunker Example

    Blog