diff --git a/index.js b/index.js index 0d340512..f57367b3 100755 --- a/index.js +++ b/index.js @@ -200,9 +200,19 @@ } hashbang = !!options.hashbang; if (!dispatch) return; - var url = (hashbang && isLocation && ~pageWindow.location.hash.indexOf('#!')) - ? pageWindow.location.hash.substr(2) + pageWindow.location.search - : pageWindow.location.pathname + pageWindow.location.search + pageWindow.location.hash; + + var url; + if(isLocation) { + var loc = pageWindow.location; + + if(hashbang && ~loc.hash.indexOf('#!')) { + url = loc.hash.substr(2) + loc.search; + } else if (hashbang) { + url = loc.search + loc.hash; + } else { + url = loc.pathname + loc.search + loc.hash; + } + } page.replace(url, null, true, dispatch); }; diff --git a/test/tests.js b/test/tests.js index ed3ab4bc..772ac68b 100644 --- a/test/tests.js +++ b/test/tests.js @@ -573,6 +573,17 @@ tests(); + it('Using hashbang, url\'s pathname not included in path', function(done){ + page.stop(); + page.callbacks = []; + page.exits = []; + page('/', function(ctx){ + expect(ctx.path).to.equal('/'); + done(); + }); + page({ hashbang: true, window: frame.contentWindow }); + }); + after(function() { hashbang = false; afterTests();