diff --git a/addon/href-to.js b/addon/href-to.js
index e4e309b..8042734 100644
--- a/addon/href-to.js
+++ b/addon/href-to.js
@@ -28,7 +28,14 @@ export default class {
handle() {
let router = this._getRouter();
- router.transitionTo(this.getUrlWithoutRoot());
+ let url = this.getUrlWithoutRoot();
+
+ if (this.isNotReplaceWithLink()) {
+ router.transitionTo(url);
+ } else {
+ router.replaceWith(url);
+ }
+
this.event.preventDefault();
}
@@ -43,6 +50,10 @@ export default class {
return !attr || attr.value !== '_blank';
}
+ isNotReplaceWithLink() {
+ return !this.target.attributes["data-href-to-replace"];
+ }
+
isNotIgnored() {
return !this.target.attributes['data-href-to-ignore'];
}
diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs
index fd0b6d8..d51b386 100644
--- a/tests/dummy/app/templates/application.hbs
+++ b/tests/dummy/app/templates/application.hbs
@@ -17,6 +17,7 @@
[About]
[First Page]
[Second Page]
+ [Second Page (with replaceWith)]
[Second Page (with dynamic params)]
[Second Page (with inner span)]
[An anchor with no href]
diff --git a/tests/unit/href-to-test.js b/tests/unit/href-to-test.js
index 2d386fd..c72cbd9 100644
--- a/tests/unit/href-to-test.js
+++ b/tests/unit/href-to-test.js
@@ -41,6 +41,20 @@ test('#isUnmodifiedLeftClick should be false for right clicks', function(assert)
assert.notOk(hrefTo.isUnmodifiedLeftClick());
});
+test('#isNotReplaceWithLink should be false if [data-href-to-replace] is present', function(assert) {
+ let event = getClickEventOnEl("");
+ let hrefTo = createHrefToForEvent(event);
+
+ assert.notOk(hrefTo.isNotReplaceWithLink());
+});
+
+test('#isNotReplaceWithLink should be true if [data-href-to-replace] is not present', function(assert) {
+ let event = getClickEventOnEl("");
+ let hrefTo = createHrefToForEvent(event);
+
+ assert.ok(hrefTo.isNotReplaceWithLink());
+});
+
test('#isNotIgnored should be false if [data-href-to-ignore] is present', function(assert) {
let event = getClickEventOnEl("");
let hrefTo = createHrefToForEvent(event);