【发布时间】:2021-08-16 05:35:07
【问题描述】:
我想要的是在我的 Angular 应用程序中为不同的页面设置不同的布局。我正在使用 Angular 12.x。
我正在尝试按照我使用路由通过 Internet 获得的建议来实现相同的功能。但是页眉/页脚被重复了。
const routes: Routes = [
{
path: '',
component: HomepageComponent
},
{ // Static Pages (Inside)
path: '',
component: StaticPageLayoutComponent,
children: [
{path: 'about-us', component: AboutUsComponent, pathMatch: 'full'},
{path: 'contact-us', component: ContactUsComponent, pathMatch: 'full'},
{path: 'faq', component: FaqComponent, pathMatch: 'full'},
{path: 'guide', component: GuideComponent, pathMatch: 'full'},
{path: 'help-center', component: HelpCenterComponent, pathMatch: 'full'},
{path: 'how-it-works', component: HowItWorksComponent, pathMatch: 'full'},
{path: 'privacy-policy', component: PrivacyPolicyComponent, pathMatch: 'full'},
{path: 'sales', component: SalesComponent, pathMatch: 'full'},
{path: 'sitemap', component: SitemapComponent, pathMatch: 'full'},
{path: 'terms-and-conditions', component: TermsAndConditionsComponent, pathMatch: 'full'}
]
}
];
app.component.html 看起来像:
<div>
<div>
<app-header-navigation></app-header-navigation>
<app-header></app-header>
</div>
<div class="content" role="main">
<router-outlet></router-outlet>
</div>
<div>
<app-footer></app-footer>
</div>
</div>
static-page-component.html 看起来像:
<div>
<div>
<app-header-navigation></app-header-navigation>
</div>
<div class="content" role="main">
<router-outlet></router-outlet>
</div>
<div>
<app-footer></app-footer>
</div>
</div>
上面2的区别在于后面的不包含<app-header></app-header>
这就是/contact-us 的样子:
对于我来说,#1、#2 和 #6 部分对于使用 StaticPageLayoutComponent 的路线不应该是可见的
对我来说,#3 和 #5 部分对于 homepage 路由不可见。请提出建议。
【问题讨论】: