提交 f6e7e623 编写于 作者: J Jason

bugfixed tabs,关闭标签时,路由未跳转

上级 88d1baf4
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<a [routerLink]="tab.route"> <a [routerLink]="tab.route">
{{tab.component && tab.component.instance.title || tab.name || tab.url}} {{tab.component && tab.component.instance.title || tab.name || tab.url}}
</a> </a>
<i nz-icon nzType="close" nzTheme="outline" (click)="onTabClose(i)"></i> <i nz-icon nzType="close" nzTheme="outline" (click)="onTabClose(i)" *ngIf="tabs.length>1"></i>
</div> </div>
<ng-container *ngFor="let tab of tabs; let i=index"> <ng-container *ngFor="let tab of tabs; let i=index">
<div class="content" [hidden]="i!=current"> <div class="content" [hidden]="i!=current">
......
...@@ -98,13 +98,25 @@ export class TabsComponent implements OnInit, OnDestroy, AfterViewInit { ...@@ -98,13 +98,25 @@ export class TabsComponent implements OnInit, OnDestroy, AfterViewInit {
} }
onTabClose(index): void { onTabClose(index): void {
const tab = this.tabs.splice(index, 1)[0]; if (this.tabs.length === 1) {
if (this.current >= index && this.current > 0) { //TODO 打开默认页
this.current--; return;
} }
const tab = this.tabs.splice(index, 1)[0];
if (tab.component) { if (tab.component) {
tab.component.destroy(); tab.component.destroy();
} }
if (this.current > index) {
this.current--;
} else if (this.current === index) {
if (this.current >= this.tabs.length) {
this.current = this.tabs.length - 1;
}
// 用修改路由的方式触发
this.router.navigate(['/admin/' + this.tabs[this.current].route]);
return;
}
} }
loadTab(index): void { loadTab(index): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册