Search code examples
angulartypescriptangular-routing

Angular 2 routing using LoadChildren


I am using this code for routing

{ path: 'dashboard', loadChildren: './dashboard#DashboardModule'},
{ path: '', children: [     
   { path: '', component:DashboardComponent, children: [
      { path: '', redirectTo:'dashboard/first',pathMatch:'full' },
      { path: 'first', component: FirstComponent },
      { path: 'second', component: SecondComponent }]
   }, 
]},

Here when the url is /dashboard I need it to route to /dashboard/first...

How can I achieve it?


Solution

  • You are already in Dashboard component. Use only first, not dashboard/first.

     { path: '', children: [
        { path: '', component:DashboardComponent ,
            children:[
              { path: '', redirectTo:'first',pathMatch:'full' },
              { path: 'first', component: FirstComponent },
              { path: 'second', component: SecondComponent },
            ]  
         }, 
      ]},