Skip to content

Commit

Permalink
Merge pull request remix-run#163 from bripkens/failing-navigation
Browse files Browse the repository at this point in the history
[fixed] Navigation to root URL can fail
  • Loading branch information
ryanflorence committed Aug 4, 2014
2 parents a597441 + 87b1c2a commit 33695b4
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 33695b4

Please sign in to comment.