page.js
page.js copied to clipboard
wrong routes when changing url in browser's address bar with hashbang set to true
Here is the test case, in Chrome,version 44.0.2403.130 m
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="js/page.js"></script>
</head>
<body>
<a href="/user/index">index</a><br/>
<a href="/user/index/?id=5">id=5</a>
<script>
page('/:group',function(data){
console.log(data);
});
page('/:group/:index', function(data){
console.log(data);
});
page('*',function(){
console.log('not found')
});
page({
hashbang: true
});
</script>
</body>
</html>
when I click the link, it all goes well. but when I change url in browser,for example from /user/index to /user/index/?id=5, the console keeps outputting not found Is this the expected behavior or not?If yes, is there other ways to debug except using page(path) in console which can't be used in mobiles?
+1
Same issue here. This PR fixes the issue : #281
Thanks, I'll see about adding tests and getting that fix in.
I tested the above PR (sadly it's been closed) It works if you don't set page.base()
otherwise you'll get double #!#!
I adopt the fix to make it work with page.base()
var hashbangPos = path.indexOf('#!'); if (hashbang && hashbangPos !== -1) { this.path = path.substr(hashbangPos+2) || '/'; } else { this.path = path.replace(pageBase, '') || '/'; }
It seems to me that TimvdLippe's PR https://github.com/visionmedia/page.js/pull/358 to solve this issue is leaner.
@paulocoghi that fix won't work when page.base() is set to non empty string
you'll get double #!#! upon dispatch / new Context()
@doctorguile I have the same problem. Have you solved it?