Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(LinkActive): Fixed active link for base url when using hash #74

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/link-active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface LinkActiveOptions {

ngAfterViewInit() {
this._sub = this.router$
.map(({path}) => this.router$.prepareExternalUrl(path))
.map(({path}) => this.router$.prepareExternalUrl(path || '/'))
.subscribe(path => {
this.checkActive(path);
});
Expand All @@ -53,12 +53,12 @@ export interface LinkActiveOptions {
let active = this.links.reduce((active, current) => {
let [href, query] = current.linkHref.split('?');

if (this.activeOptions.exact) {
return active ? active : href === path;
} else {
return active ? active : path.startsWith(href);
}
}, false);
if (this.activeOptions.exact) {
return active ? active : href === path;
} else {
return active ? active : path.startsWith(href);
}
}, false);

let activeClasses = this.activeClass.split(' ');
activeClasses.forEach((activeClass) => {
Expand Down
19 changes: 19 additions & 0 deletions spec/link-active.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ describe('Link Active', () => {
expect(link.getAttribute('class')).toEqual('active');
});
})));

describe('With Hash', () => {
it('should add the provided class to the active element', async(inject([TestComponentBuilder, Router, LocationStrategy], (tcb, router$, ls) => {
ls.internalBaseHref = '#';

router$.next({
path: '/'
});

return compile(tcb, '<a linkActive="active" linkTo="/">Page</a>')
.then((fixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
let link: Element = compiled.querySelector('a');

expect(link.getAttribute('class')).toEqual('active');
});
})));
});
});