angular - 将应用内容放在 mat-sidenav-content 中
问题描述
我有一个使用 FlexLayoutModule 的应用程序。我有一个对 Web 和移动设备都响应的标头,但是我不确定应该如何正确构建我的应用程序。我想在 mat-sidenav-container 中添加我的应用程序内容。
header.component.html
<div>
<mat-toolbar color="primary">
<div fxShow="true" fxHide.gt-sm="true">
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon>Menu</mat-icon>
</button>
</div>
<a mat-button class="companyName" routerLink="/">
<span>Wilderness Adventures</span>
</a>
<span class="example-spacer"></span>
<div fxShow="true" fxHide.lt-md="true">
<a mat-button routerLink="/about-us">Latest listings</a>
<a mat-button routerLink="/prices">Experiences</a>
<a mat-button routerLink="/start-page">Hot deal</a>
<mat-icon>home</mat-icon>Become a host
</div>
</mat-toolbar>
<mat-sidenav-container fxFlexFill class="example-container">
<mat-sidenav color="primary" #sidenav fxLayout="column" mode="over" opened="false" fxHide.gt-sm="true">
<div fxLayout="column">
<a mat-button routerLink="/about-us">Latest listings</a>
<a mat-button routerLink="/prices">Experiences</a>
<a mat-button routerLink="/start-page">Hot deal</a>
<mat-icon>home</mat-icon>Become a host
</div>
</mat-sidenav>
<mat-sidenav-content fxFlexFill>
<!--should app content go here-->
</mat-sidenav-content>
</mat-sidenav-container>
</div>
app.component.html
<app-landing></app-landing>
<router-outlet></router-outlet>
这是我的应用程序的完整堆栈闪电战
https://stackblitz.com/edit/angular-ivy-gygw2g?file=src/app/app.component.html
如果您看到该应用程序,您会注意到我的内容位于 mat-sidenav-container 下方,但我不想有蓝色块
解决方案
这部分不起作用,因为您希望在导航到另一条路线时替换您的登录页面:
<app-landing></app-landing>
<router-outlet></router-outlet>
您的Header
组件更像是一个主要/核心组件,因为它包含标题和mat-sidenav-container
您的路由内容将显示的位置。
但是保留它的名称作为示例,您可以将它直接包含到您的 AppComponent 中,将您的router-outlet
放入它的标签中:
<app-header><router-outlet></router-outlet></app-header
然后您可以使用内容投影来放置router-outlet into the mat-sidenav-container
:
<mat-sidenav-container>
<ng-content></ng-content>
</mat-sidenav-container>
最后,要将登录页面显示到 sidenav 容器中,请在 AppRoutingMOdule 中声明访问它的路由:
const routes: Routes = [{path: '', component: LandingComponent}]
并将 a 添加routerlink
到 HeaderComponent 的导航栏中
推荐阅读
- java - JAVA 在 JMenuItem[] 构造函数中声明未初始化的 JMenuItem() 项
- anypoint-studio - 将 Mulesoft 运行时版本更新到 4.2.1 时出错
- spring-boot - SCDF 自定义 spring 云流源应用程序不会将生成的消息写入 Kafka 主题
- android - 应用程序启动时android picasso不起作用
- docker - 如何管理 docker 容器的 SELinux 上下文?
- sql - SQLite 别名 (AS) 不在同一个查询中工作
- spring - 如何在反序列化之前使用 java reactor webclient 打印 responseBody
- javascript - 当我使用 ' ; '而不是' && ',输出发生变化,我需要帮助理解它
- spring - StateMachineRuntimePersister 实例化失败,因为 Spring 无法找到其依赖的 bean MongoDbStateMachineRepository
- sql - Ignite:一个简单的group by sql查询花费大约40s,2000万条数据