【发布时间】:2019-11-11 08:55:19
【问题描述】:
我正在创建一个包含多个页面的 Web 应用程序,每个页面中都有动态部分。我希望这些部分中的每一个都使用角度路由器。
我试过简单地将一个命名的路由器插座放在组件中,但它似乎不起作用......有什么想法吗?
这是我的一般设置。
应用模板
<main>
<router-outlet></router-outlet>
</main>
应用模块
const routes: Routes = [
{
path: 'page',
component: PageModule
}
];
@NgModule({
imports: [PageModule, RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
页面模板:
<tabset>
<tab>
<router-outlet name="section1"></router-outlet>
</tab>
<tab>
<router-outlet name="section2"></router-outlet>
</tab>
</tabset>
页面模块
const routes: Routes = [
{
path: '',
component: PageComponent,
},
{
path: 'section1-view1',
component: View1Component,
outlet: 'section1',
},
{
path: 'section1-view2',
component: View2Component,
outlet: 'section1',
}
// More routes ...
];
@NgModule({
declarations: [
PageComponent,
View1Component,
View2Component
],
imports: [
RouterModule.forChild(routes),
CommonModule,
TabsetModule
]
})
export class PageModule { constructor(){} }
【问题讨论】:
-
您是在寻找路线来确定要显示哪个选项卡或确定每个选项卡上显示什么?
-
要在路由页面中路由吗?
-
不清楚您要完成什么。你的意思是每个部分都应该有一个url链接?像在角度文档页面中一样? (喜欢这个链接:angular.io/guide/ngmodules#angular-modularity)
-
@KautilyaKatiha,是的!我想在路由页面内路由。 :)
-
我希望每个选项卡的内容由路由控制,并且我希望这些选项卡位于也通过路由器包含的页面上。
标签: javascript angular angular7 angular-routing angular7-router