Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Different modules same routing

I am having two main routes, both loading same child module. Is there any possible way to have two routes with same name on the child module that loads two different components with respect to the main route.

Main Routes:

export const ROUTES: Routes = [{
    path: 'first',
    loadChildren: './features/common#CommonModule',
    canActivate: [AppAuthGuard]
}, {
    path: 'second',
    loadChildren: './features/common#CommonModule',
    canActivate: [AppAuthGuard]
}]

Now I'm expecting the common module to have routes something like this

export const routes = [{
        path: 'list', component: FirstListComponent, pathMatch: 'full' }
    },{
        path: 'list', component: SecondListComponent, pathMatch: 'full' }
    }]

So, I want something like

  • If route is first/list, then FirstListComponent should be loaded.
  • If route is second/list, then SecondListComponent should be loaded.

I know that the order of the routes matters. And the proposed way is not possible. Can anyone suggest any possible way to achieve this.

like image 594
Teja Avatar asked Nov 22 '25 16:11

Teja


1 Answers

Please set path like this

export const routes = [{
        path: 'first/list', component: FirstListComponent, pathMatch: 'full' }
    },{
        path: 'second/list', component: SecondListComponent, pathMatch: 'full' }
    }]
like image 136
baj9032 Avatar answered Nov 24 '25 08:11

baj9032



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!