Breadcrumb面包屑
显示当前页面在系统层级结构中的位置,并能向上返回。
何时使用
- 当系统拥有超过两级以上的层级结构时;
- 当需要告知用户『你在哪里』时;
- 当需要向上导航的功能时。
单独引入此组件
想要了解更多关于单独引入组件的内容,可以在快速上手页面进行查看。
import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
代码演示
最简单的用法。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-basic',
template: `
<nz-breadcrumb>
<nz-breadcrumb-item>
Home
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a>Application List</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
An Application
</nz-breadcrumb-item>
</nz-breadcrumb>
`
})
export class NzDemoBreadcrumbBasicComponent {}
和 RouterLink 进行结合使用。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-router',
template: `
<nz-breadcrumb>
<nz-breadcrumb-item>
<a [routerLink]="['../../']">Home</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
Breadcrumb
</nz-breadcrumb-item>
</nz-breadcrumb>
`
})
export class NzDemoBreadcrumbRouterComponent {}
使用 nzSeparator
可以自定义分隔符。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-separator',
template: `
<h4>String</h4>
<nz-breadcrumb nzSeparator=">">
<nz-breadcrumb-item>
Home
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a>Application List</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
An Application
</nz-breadcrumb-item>
</nz-breadcrumb>
<br />
<h4>TemplateRef</h4>
<nz-breadcrumb [nzSeparator]="iconTemplate">
<nz-breadcrumb-item>
Home
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a>Application List</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
An Application
</nz-breadcrumb-item>
</nz-breadcrumb>
<ng-template #iconTemplate><i nz-icon nzType="arrow-right"></i></ng-template>
`,
styles: [
`
h4:first-child {
margin-top: 0;
}
h4 {
margin: 16px 0;
font-size: 14px;
line-height: 1;
font-weight: normal;
}
`
]
})
export class NzDemoBreadcrumbSeparatorComponent {}
图标放在文字前面。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-withIcon',
template: `
<nz-breadcrumb>
<nz-breadcrumb-item>
<i nz-icon nzType="home"></i>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a><i nz-icon nzType="user"></i><span>Application List</span></a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
Application
</nz-breadcrumb-item>
</nz-breadcrumb>
`
})
export class NzDemoBreadcrumbWithIconComponent {}
通过配置 router.data
自动生成面包屑。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-auto',
template: `
<nz-breadcrumb [nzAutoGenerate]="true">
Please refer to StackBlitz demo at https://stackblitz.com/edit/ng-zorro-breadcrumb-auto
</nz-breadcrumb>
`
})
export class NzDemoBreadcrumbAutoComponent {}
面包屑支持下拉菜单。
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-breadcrumb-dropdown',
template: `
<nz-breadcrumb>
<nz-breadcrumb-item>
Ant Design
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a>Component</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item [nzOverlay]="menu">
<a href>An Application</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
Button
</nz-breadcrumb-item>
</nz-breadcrumb>
<nz-dropdown-menu #menu="nzDropdownMenu">
<ul nz-menu nzSelectable>
<li nz-menu-item>General</li>
<li nz-menu-item>Layout</li>
<li nz-menu-item>Navigation</li>
</ul>
</nz-dropdown-menu>
`
})
export class NzDemoBreadcrumbDropdownComponent {}
API
nz-breadcrumbcomponent
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
[nzSeparator] | 分隔符自定义 | string | TemplateRef<void> | '/' |
[nzAutoGenerate] | 自动生成 Breadcrumb | boolean | false |
使用 [nzAutoGenerate]
时,需要在路由类中定义 data
:
{
path: 'path',
component: SomeComponent,
data: {
breadcrumb: 'Display Name'
}
}
对于懒加载路由,应该在父层路由写 data
:
{
path: 'first',
loadChildren: './first/first.module#FirstModule',
data: {
breadcrumb: 'First'
},
}
当前内容版权归 ant.design 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ant.design .