2017-10-10 96 views
-1

我有两条主要路由,都加载相同的子模块。是否有任何可能的方法在子模块上有两个相同名称的路线,它们针对主路线加载两个不同的组件。Angular 2不同的模块相同路由

主要航线

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

现在我期待的通用模块有路线是这样的

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

所以,我想是这样

  • 如果路线是第一/列表, n FirstListComponent应该被加载。
  • 如果路线是秒/列表,则SecondListComponent应该被加载。

我知道路线的顺序很重要。所提议的方式是不可能的。任何人都可以提出任何可能的方法来达到这个

回答

1

请设置这样

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

感谢您的答复路径。但是如果我这样使用,那么总路线将分别是* first/first/list *和* second/second/list *。 – Teja

+0

@Teja:请参阅角色https://angular.io/guide/router#child-routing-component的路由文件。所以你会对路由有更好的想法。 – baj9032