Skip to content

Commit

Permalink
[fixed] Navigation to root URL can fail
Browse files Browse the repository at this point in the history
Navigation to root URL can fail when the URLStore is setup with
location strategy 'hash'. This happens because URLStore.push
verifies the current path. Unfortunately the used currentPath is
not valid for the location strategies *hash* and *history*.

This change changes URLStore.push so that it uses the location
strategy specific current path. This value is already provided
by URLStore.getCurrentPath.
  • Loading branch information
bripkens committed Aug 3, 2014
1 parent a597441 commit 87b1c2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/stores/URLStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ var URLStore = {
getCurrentPath: function () {
if (_location === 'history')
return getWindowPath();

if (_location === 'hash')
return window.location.hash.substr(1);

return _currentPath;
},

/**
* Pushes the given path onto the browser navigation stack.
*/
push: function (path) {
if (path === _currentPath)
if (path === this.getCurrentPath())
return;

if (_location === 'disabledHistory')
Expand Down Expand Up @@ -193,6 +193,7 @@ var URLStore = {
}

_location = null;
_currentPath = '/';
}

};
Expand Down
23 changes: 23 additions & 0 deletions specs/URLStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ describe('when going back in history', function () {
expect(error).toEqual(true);
});
});

describe('when navigating back to the root', function() {
beforeEach(function () {
// not all tests are constructing and tearing down the URLStore.
// Let's set it up correctly once and then tear it down to ensure that all
// variables in the URLStore module are reset.
URLStore.setup('hash');
URLStore.teardown();

// simulating that the browser opens a page with #/dashboard
window.location.hash = '/dashboard';
URLStore.setup('hash');
});

afterEach(function () {
URLStore.teardown();
});

it('should have the correct path', function () {
URLStore.push('/');
expect(window.location.hash).toEqual('#/');
});
});

0 comments on commit 87b1c2a

Please sign in to comment.