【发布时间】:2018-03-13 15:52:00
【问题描述】:
我是 Angular 4 的新手。我想要实现的是为我的应用程序中的不同页面设置不同的布局页眉和页脚。我有三种不同的情况:
- 登录、注册页面(无页眉、无页脚)
路由:['login','register']
- 营销网站页面(这是根路径,它有页眉和页脚,这些部分大多在登录之前出现)
路线:['','about','contact']
- 应用登录页面(我在此部分中为所有应用页面设置了不同的页眉和页脚,但此页眉和页脚与营销网站页眉和页脚不同)
路线:['dashboard','profile']
我通过在路由器组件 html 中添加页眉和页脚来临时运行该应用程序。
请告诉我一个更好的方法。
这是我的代码:
app\app.routing.ts
const appRoutes: Routes = [
{ path: '', component: HomeComponent},
{ path: 'about', component: AboutComponent},
{ path: 'contact', component: ContactComponent},
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'profile', component: ProfileComponent },
// otherwise redirect to home
{ path: '**', redirectTo: '' }
];
export const routing = RouterModule.forRoot(appRoutes);
app.component.html
<router-outlet></router-outlet>
app/home/home.component.html
<site-header></site-header>
<div class="container">
<p>Here goes my home html</p>
</div>
<site-footer></site-footer>
app/about/about.component.html
<site-header></site-header>
<div class="container">
<p>Here goes my about html</p>
</div>
<site-footer></site-footer>
app/login/login.component.html
<div class="login-container">
<p>Here goes my login html</p>
</div>
app/dashboard/dashboard.component.html
<app-header></app-header>
<div class="container">
<p>Here goes my dashboard html</p>
</div>
<app-footer></app-footer>
我在 stack-overflow 上看到了 this question,但我没有从那个答案中得到清晰的画面
【问题讨论】:
-
这个链接有几种方法可以做到这一点:blog.angularindepth.com/…
标签: angular angular-routing angular-template angular-router