millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

Why do `setting window.location.hash` and `hasher.setHash` result in different behavior of question mark `%3F`? #143

Open lzl124631x opened 8 years ago

lzl124631x commented 8 years ago

Demo here

console.clear();
//crossroads.normalizeFn = crossroads.NORM_AS_OBJECT;
crossroads.addRoute(
    'page{?url}',
    function (query) {
    console.log(query);
});

hasher.init();
hasher.changed.add(function(hash) {
    crossroads.parse(hash);
})
hasher.setHash('page?url=begin%3Fend%2F');
console.log(hasher.getHash());
window.location.hash = 'page?url=begin%3Fend%2F';
console.log(hasher.getHash());

As you can see, if I directly set the window.location.hash (which is more commonly used since clicking on has the same behavior), the question mark is gone, while the question mark is kept if I use hasher.setHash? How come this discrepancy?