Skip to content

Commit

Permalink
fix(abc:sidebar-nav): fix invalid link when specified base-href of ha…
Browse files Browse the repository at this point in the history
…sh route
  • Loading branch information
cipchk committed Apr 18, 2018
1 parent cb519b5 commit 6df9bed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/abc/sidebar-nav/sidebar-nav.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions packages/abc/sidebar-nav/sidebar-nav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ describe('abc: sidebar-nav', () => {
fixture.detectChanges();
expect(getEl<HTMLElement>(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<HTMLElement>(floatingShowCls, true);
expect(containerEl).not.toBeNull();
expect(containerEl.querySelector('a').href).toContain(baseHref);
page.hideSubMenu();
expect(router.navigateByUrl).not.toHaveBeenCalledWith(baseHref);
});
});

describe('[underPad]', () => {
Expand Down

0 comments on commit 6df9bed

Please sign in to comment.