diff --git a/modules/stores/URLStore.js b/modules/stores/URLStore.js index a55238a269..e03672e2b7 100644 --- a/modules/stores/URLStore.js +++ b/modules/stores/URLStore.js @@ -58,10 +58,10 @@ var URLStore = { getCurrentPath: function () { if (_location === 'history') return getWindowPath(); - + if (_location === 'hash') return window.location.hash.substr(1); - + return _currentPath; }, @@ -69,7 +69,7 @@ var URLStore = { * Pushes the given path onto the browser navigation stack. */ push: function (path) { - if (path === _currentPath) + if (path === this.getCurrentPath()) return; if (_location === 'disabledHistory') @@ -193,6 +193,7 @@ var URLStore = { } _location = null; + _currentPath = '/'; } }; diff --git a/specs/URLStore.spec.js b/specs/URLStore.spec.js index ce6a5c0a5b..0225c72e4e 100644 --- a/specs/URLStore.spec.js +++ b/specs/URLStore.spec.js @@ -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('#/'); + }); +});