page.js icon indicating copy to clipboard operation
page.js copied to clipboard

wrong routes when changing url in browser's address bar with hashbang set to true

Open ahcheqiu opened this issue 10 years ago • 7 comments

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?

ahcheqiu avatar Aug 12 '15 07:08 ahcheqiu

+1

asfktz avatar Sep 13 '15 21:09 asfktz

Same issue here. This PR fixes the issue : #281

alberthier avatar Sep 16 '15 22:09 alberthier

Thanks, I'll see about adding tests and getting that fix in.

matthewp avatar Jan 13 '18 17:01 matthewp

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, '') || '/'; }

doctorguile avatar Feb 26 '18 18:02 doctorguile

It seems to me that TimvdLippe's PR https://github.com/visionmedia/page.js/pull/358 to solve this issue is leaner.

paulocoghi avatar Feb 26 '18 20:02 paulocoghi

@paulocoghi that fix won't work when page.base() is set to non empty string

you'll get double #!#! upon dispatch / new Context()

doctorguile avatar Feb 27 '18 00:02 doctorguile

@doctorguile I have the same problem. Have you solved it?

yancy-li avatar Jun 15 '18 04:06 yancy-li