Skip to content

Commit

Permalink
Merge pull request #447 from visionmedia/root-hash
Browse files Browse the repository at this point in the history
Prevent going to the root when setting up the initial hashchange route
  • Loading branch information
matthewp authored Jan 17, 2018
2 parents 1ecd56e + cf36f16 commit c10ebe9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
11 changes: 11 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c10ebe9

Please sign in to comment.