Angular 2 Different modules same routing

人盡茶涼 提交于 2019-12-12 05:49:26

问题


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.


回答1:


Please set path like this

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


来源:https://stackoverflow.com/questions/46663700/angular-2-different-modules-same-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!