Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble parsing query string on default route #96

Closed
lbssousa opened this issue Mar 28, 2017 · 4 comments
Closed

Trouble parsing query string on default route #96

lbssousa opened this issue Mar 28, 2017 · 4 comments

Comments

@lbssousa
Copy link

lbssousa commented Mar 28, 2017

I'm trying to parse a query string passed to my default route using navigo. Example URL:

http://myhost/myproject?check=1

Example code:

var router = new Navigo('http://myhost/myproject', false, '#!');

router.on(function (query) {
    console.log('Query string: ' + query);
}).resolve();

If I initialize my router with useHash = false, then I'm unable to parse the query check=1 (the query parameter in the handler function above only returns an empty string). However, if I set useHash = true, then I would be able to parse it, provided that I rewrite the URL above as follows:

http://myhost/myproject/#!?check=1
krasimir pushed a commit that referenced this issue Mar 30, 2017
@krasimir
Copy link
Owner

Hey @lbssousa,

I added a unit test but no luck reproducing your issue. I created a simple page with the following code:

var router = new Navigo('http://home.dev/Krasimir/_tests/navigo/96/', false, '#!');

  router.on(function (query) {
    console.log('Query string: ' + query);
  }).resolve();

And when I opened http://home.dev/Krasimir/_tests/navigo/96/?test=1 I got:
image

So I'm not able to replicate the issue locally. Maybe if you provide an example. Also let me know OS and browser version. Do you use the latest Navigo release?

@lbssousa
Copy link
Author

lbssousa commented Mar 31, 2017

Hmmm... Sorry, but I wasn't too accurate in my issue description.

In fact, if I initialize the router with an explicit root URL (as in your test case), I'm able to catch the query string. The real issue occurs when I initialize the router with a default root URL (passing null as the first argument). Taking your example code, it should be

var router = new Navigo(null, false, '#!');

  router.on(function (query) {
    console.log('Query string: ' + query);
  }).resolve();

In this case, I'm getting only an empty string for query.

krasimir pushed a commit that referenced this issue Apr 1, 2017
@krasimir
Copy link
Owner

krasimir commented Apr 1, 2017

I finally reproduced the bug. Fixed in 4.5.1. Can you please try and let me know if it works on your machine.

@lbssousa
Copy link
Author

lbssousa commented Apr 3, 2017

Yes! I've just upgraded my navigo version and now it parses the query string correctly!

Thank you very much!

@lbssousa lbssousa closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants