角2不同的模块相同的路由 [英] Angular 2 Different modules same routing

查看:46
本文介绍了角2不同的模块相同的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条主要路线,两个路线都装载相同的子模块.是否有可能在子模块上具有两个具有相同名称的路由,从而相对于主路由加载两个不同的组件.

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.

主要路线:

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

  • 如果路由为 first/list ,则应加载 FirstListComponent .
  • 如果路由为 second/list ,则应加载 SecondListComponent .
  • 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.

推荐答案

请设置这样的路径

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

这篇关于角2不同的模块相同的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆