fix(RouterLink): do not prevent default behavior if target set on anchor element

If the anchor element on which the "router-link" directive is present has a target
attribute other than "_self," the handler will not prevent default behavior of
the browser.

Closes #4233
Closes #5082
This commit is contained in:
Jeff Cross
2015-11-02 15:11:57 -08:00
parent a9b1270a5a
commit a69e7fe297
4 changed files with 71 additions and 7 deletions

View File

@ -26,4 +26,19 @@ describe('hash routing example app', function() {
expect(element(by.css('goodbye-cmp')).getText()).toContain('goodbye');
});
it('should open in new window if target is _blank', () => {
var URL = 'playground/src/hash_routing/index.html';
browser.get(URL + '#/');
waitForElement('hello-cmp');
element(by.css('#goodbye-link-blank')).click();
expect(browser.driver.getCurrentUrl()).not.toContain('#/bye');
browser.getAllWindowHandles().then(function(windows) {
browser.switchTo()
.window(windows[1])
.then(function() { expect(browser.driver.getCurrentUrl()).toContain("#/bye"); });
});
});
});

View File

@ -29,6 +29,9 @@ class GoodByeCmp {
<nav>
<a href="#/" id="hello-link">Navigate via href</a> |
<a [router-link]="['/GoodbyeCmp']" id="goodbye-link">Navigate with Link DSL</a>
<a [router-link]="['/GoodbyeCmp']" id="goodbye-link-blank" target="_blank">
Navigate with Link DSL _blank target
</a>
</nav>
<router-outlet></router-outlet>
`,