swipely / aviator

Aviator is a single-page front-end router built for modularity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query string parsing doesn't work with push state disabled?

nicolashery opened this issue · comments

Given this code:

var Handler = {
  index: function(req) {
    console.log(req);
  }
};

Aviator.pushStateEnabled = false;

Aviator.setRoutes({
  '/users': {
    target: Handler,
    '/': 'index',
    '/:id': 'index'
  }
});

Aviator.dispatch();

Aviator.navigate('/users/123?foo=bar');

I get a Request object with queryParams empty and queryString null?

If I comment out the line Aviator.pushStateEnabled = false though, I get the expected Request object, with the query string parsed properly.

I was testing this in Chrome 34. Any ideas what's going on?

Thanks!

Thats unfortunate. I'll get right on that! Thanks for creating this issue :)

Thanks!

I also bumped into the following "corner case", might be related...

Given this code:

var Handler = {
  index: function(req) {
    console.log(req);
  }
};

Aviator.pushStateEnabled = false;

Aviator.setRoutes({
  '/users': {
    target: Handler,
    '/': 'index'
  },
  '/cats/:id': {
    target: Handler,
    '/': 'index'
  }
});

Aviator.dispatch();

Aviator.navigate('/users?foo=bar');

I get a Uncaught TypeError: Cannot read property 'indexOf' of undefined (aviator.js:898).

But if I comment out the pushStateEnabled = false, it works as expected.

@nicolashery that seems unrelated, but definitely a bug with hash routing. Could you create another issue for that one? Thanks

Done in #57

Thanks for the quick turnaround @hojberg!

I tried it out with my first example of this issue. I get the expected queryParams: {foo: 'bar'}, yay! However I notice that we now have namedParams: {id: '123?foo=bar'} :-/

Is that a new bug, or could that be related to #57?

Sorry about this! :)

That could very much be #57.

Also don't apologize :) You're helping make Aviator more awesome! Thank you.

My pleasure :)

Btw, I just saw you had #59 up, so I went ahead and tested it, and it seems to fix both my previous comment and #57 :D Can't wait to see it merged and a new version tagged!

@nicolashery I tagged v0.4.1 with the 2 fixes :)

@hojberg Wonderful. Thanks again for quickly fixing this!