diff --git a/packages/abc/sidebar-nav/sidebar-nav.component.ts b/packages/abc/sidebar-nav/sidebar-nav.component.ts index d259d18863..e2430a49ef 100644 --- a/packages/abc/sidebar-nav/sidebar-nav.component.ts +++ b/packages/abc/sidebar-nav/sidebar-nav.component.ts @@ -1,6 +1,6 @@ import { Component, ElementRef, Renderer2, Inject, OnInit, OnDestroy, HostListener, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, EventEmitter } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; -import { DOCUMENT } from '@angular/common'; +import { DOCUMENT, LocationStrategy } from '@angular/common'; import { Subscription } from 'rxjs/Subscription'; import { debounceTime, filter } from 'rxjs/operators'; import { FromEventObservable } from 'rxjs/observable/FromEventObservable'; @@ -33,6 +33,7 @@ export class SidebarNavComponent implements OnInit, OnDestroy { private menuSrv: MenuService, public settings: SettingsService, private router: Router, + private locationStrategy: LocationStrategy, private render: Renderer2, private cd: ChangeDetectorRef, @Inject(DOCUMENT) private doc: any, @@ -62,6 +63,11 @@ export class SidebarNavComponent implements OnInit, OnDestroy { if (url && url.startsWith('#')) { url = url.slice(1); } + // 如果配置了bashHref 则去掉baseHref + const baseHerf = this.locationStrategy.getBaseHref(); + if (baseHerf) { + url = url.slice(baseHerf.length); + } this.router.navigateByUrl(url); this.onSelect(this.menuSrv.getPathByUrl(url).pop()); this.hideAll(); diff --git a/packages/abc/sidebar-nav/sidebar-nav.spec.ts b/packages/abc/sidebar-nav/sidebar-nav.spec.ts index 91b48bf153..87b67a6545 100644 --- a/packages/abc/sidebar-nav/sidebar-nav.spec.ts +++ b/packages/abc/sidebar-nav/sidebar-nav.spec.ts @@ -178,6 +178,21 @@ describe('abc: sidebar-nav', () => { fixture.detectChanges(); expect(getEl(floatingShowCls, true)).toBeNull(); }); + it('#59', () => { + const baseHref = '/testbh'; + TestBed.overrideProvider(APP_BASE_HREF, { + useFactory: () => baseHref, deps: [] + }); + createComp(); + setSrv.layout.collapsed = true; + fixture.detectChanges(); + page.showSubMenu(); + const containerEl = getEl(floatingShowCls, true); + expect(containerEl).not.toBeNull(); + expect(containerEl.querySelector('a').href).toContain(baseHref); + page.hideSubMenu(); + expect(router.navigateByUrl).not.toHaveBeenCalledWith(baseHref); + }); }); describe('[underPad]', () => {