我有一个Angular 5应用程序,可以动态加载功能模块并在主路由器插座中显示其内容。下面的代码显示了我的基本配置:
来自根模块(主路由器插座)的app.component:
<router-outlet></router-outlet>
root的路由配置(模块是从传递的URL动态加载的):
const routes: Routes = [
{ path: 'module1', loadChildren: ...},
{ path: 'module2', loadChildren: ...}
];
export const AppRoutes = RouterModule.forRoot(routes);
其中一个功能模块的示例路由:
const routes: Routes = [
{ path: 'report/:reportId', component: ReportComponent}
];
export const AppRoutes = RouterModule.forChild(routes);
及其app.component包含另一个路由器插座:
<router-outlet></router-outlet>
这样的配置工作正常 - 如果我去mysite.com/module1,然后加载module1并且angular控制功能模块路由器,所以访问mysite.com/module1/report/2会在功能模块内显示ReportComponent&# 39; s路由器插座。
我现在要做的是将TabsComponent添加到我的主模块,以便能够从多个选项卡组成页面,其中每个选项卡将包含一个特定模块。我想以某种方式使用已经指定的root路由,而不是手动将其重复为TabsComponent的子项,并将功能模块加载到TabsComponent的路由器插座中。
tabs.component:
<tabs-navigation></tabs-navigation>
<router-outlet></router-outlet>
tabs.configuration(在运行时通过http动态加载):
{
pageId: "page1",
tabs: [{
tabId: "tab1",
module: "module1",
params: "report/2"
}, {
tabId: "tab2",
module: "module2"
}]
}
我的路由配置中的另一行是root:
{ path: 'tabs/:pageId', component: TabsComponent}
从现在开始访问mysite.com/tabs/page1时,我想:
我的两个问题是:
答案 0 :(得分:0)
@syntax_error这就是我的做法。我对Angular也有类似的要求。我的应用程序有一个页面,显示多个用户,每个用户都有一个对应的详细视图/路线。 例如
用户A的信息也具有子状态(家庭信息,城市信息,乡间别墅均为用户A信息的子路线) 大多数顶级路线就是这种情况。 我已经使用ngrx和mat-tab解决了我的问题。外壳组件的对齐方式如下。
<header></header>
<my-tab></my-tab>
<router-outlet></router-outlet>
<footer></footer>
my-tab组件负责侦听可观察的事件,该事件可在更新选项卡列表时触发。只要可观察对象得到响应,选项卡组件就会呈现更新的选项卡。 单个标签表示为
{
id: unique tab id,
isActive: is tab current active,
isHomeTab: denotes if a tab is home tab or user tab
currentViewURL: current route url for this tab
timestamp: time in ms when this tab was created //used to decide the order in which tabs are created
}
流程如下,
希望这可以帮助您或其他人决定如何继续使用标签实现。