diff --git a/index.js b/index.js index 925b2535..c7e59af9 100755 --- a/index.js +++ b/index.js @@ -157,7 +157,7 @@ var loc = window.location; if(this._hashbang && ~loc.hash.indexOf('#!')) { - url = loc.hash.substr(2) + loc.search; + url = loc.hash.substr(2) + (~loc.hash.indexOf('?') ? '' : loc.search); } else if (this._hashbang) { url = loc.search + loc.hash; } else { diff --git a/page.js b/page.js index 99c0a6f5..83ca6ecf 100644 --- a/page.js +++ b/page.js @@ -557,7 +557,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; var loc = window.location; if(this._hashbang && ~loc.hash.indexOf('#!')) { - url = loc.hash.substr(2) + loc.search; + url = loc.hash.substr(2) + (~loc.hash.indexOf('?') ? '' : loc.search); } else if (this._hashbang) { url = loc.search + loc.hash; } else { diff --git a/test/support/jsdom.js b/test/support/jsdom.js index 620e1b12..360e091d 100644 --- a/test/support/jsdom.js +++ b/test/support/jsdom.js @@ -8,7 +8,7 @@ function setupJsdom(options, next) { function setupGlobals(window) { window.console = console; if(window.location.protocol !== 'file:') - window.history.replaceState(null, '', '/'); + window.history.replaceState(null, '', '/' + options.qs || ''); global.window = window; global.location = window.location; global.document = window.document; diff --git a/test/tests.js b/test/tests.js index 7ab7a064..0800b106 100644 --- a/test/tests.js +++ b/test/tests.js @@ -800,6 +800,30 @@ }); }); + describei('When hashbang option enabled with base query params', function() { + before(function(done){ + jsdomSupport.setup({ + qs: '?hello=there' + }, done); + }); + + it('prevents duplicate query params added to hash', function(done) { + var count = 0; + + baseRoute = function () { + expect(window.location.search).to.equal('?hello=there'); + expect(window.location.hash).to.equal('#!?hello=there'); + + count++; + count === 2 && done(); + }; + + page({ hashbang: true }); + page({ hashbang: true }); + }); + }); + + describe('Route', function() { before(function(done) { beforeTests(null, done);