fix(router): make router links work on non-a tags

This commit is contained in:
vsavkin
2016-06-28 16:47:13 -07:00
parent 810c722413
commit 8c45aebc18
5 changed files with 103 additions and 15 deletions

View File

@ -476,7 +476,6 @@ describe('Integration', () => {
})));
});
describe('router links', () => {
it('should support string router links',
fakeAsync(
@ -504,6 +503,31 @@ describe('Integration', () => {
expect(fixture.debugElement.nativeElement).toHaveText('team 33 { simple, right: }');
})));
it('should support using links on non-a tags',
fakeAsync(
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
const fixture = createRoot(tcb, router, RootCmp);
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: StringLinkButtonCmp},
{path: 'simple', component: SimpleCmp}
]
}]);
router.navigateByUrl('/team/22/link');
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { link, right: }');
const native = fixture.debugElement.nativeElement.querySelector('button');
native.click();
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('team 33 { simple, right: }');
})));
it('should support absolute router links',
fakeAsync(
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
@ -1023,6 +1047,15 @@ function expectEvents(events: Event[], pairs: any[]) {
class StringLinkCmp {
}
@Component({
selector: 'link-cmp',
template: `<button routerLink
="/team/33/simple">link</button>`,
directives: ROUTER_DIRECTIVES
})
class StringLinkButtonCmp {
}
@Component({
selector: 'link-cmp',
template: `<router-outlet></router-outlet><a [routerLink]="['/team/33/simple']">link</a>`,
@ -1159,7 +1192,7 @@ class RelativeLinkInIfCmp {
precompile: [
BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp,
RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp,
QueryParamsAndFragmentCmp
QueryParamsAndFragmentCmp, StringLinkButtonCmp
]
})
class RootCmp {