Skip to content
Open
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
21 changes: 19 additions & 2 deletions addon/href-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,26 @@ export default class {
return this.applicationInstance.lookup('service:router');
}

_getRootUrl() {
_getLocationImplementation() {
let router = this._getRouter();

return router.get('location.implementation');
}

_getRouterRootUrl() {
let router = this._getRouter();
let rootURL = router.get('rootURL');

return router.get('rootURL');
}

_getRootUrl() {
let locationType = this._getLocationImplementation();

if (locationType === 'hash') {
return '#/';
}

let rootURL = this._getRouterRootUrl();

if (rootURL.charAt(rootURL.length - 1) !== '/') {
rootURL = rootURL + '/';
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/href-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,33 @@ test('#getUrlWithoutRoot should remove the rootUrl', function(assert) {
hrefTo._getRootUrl = () => '/';
assert.equal(hrefTo.getUrlWithoutRoot(), '/a/inbox', 'the url shouldn\'t include the rootUrl');
});

module('#_getRootUrl', function() {
test('it builds auto location roots correctly', function(assert) {
let event = getClickEventOnEl("<a href='/a/inbox'>");
let hrefTo = createHrefToForEvent(event);

hrefTo._getLocationImplementation = () => 'auto';
hrefTo._getRouterRootUrl = () => '/';

assert.equal(hrefTo._getRootUrl(), '/');

hrefTo._getRouterRootUrl = () => '/app';

assert.equal(hrefTo._getRootUrl(), '/app/');
});

test('it builds hash location roots correctly', function(assert) {
let event = getClickEventOnEl("<a href='/a/inbox'>");
let hrefTo = createHrefToForEvent(event);

hrefTo._getLocationImplementation = () => 'hash';
hrefTo._getRouterRootUrl = () => '/';

assert.equal(hrefTo._getRootUrl(), '#/');

hrefTo._getRouterRootUrl = () => '/app';

assert.equal(hrefTo._getRootUrl(), '#/');
});
});