olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Bad handling of links w/ query strings without routes #43

Closed agildehaus closed 12 years ago

agildehaus commented 12 years ago

This affects the latest version, 0.9.1.

A simple page showing this issue can be found here: http://goo.gl/42KGV

If I have a link with no matching route, usually it works well ... until I found that this doesn't work when the link has a query string attached.

a href="/blah.html?foo=bar"

will cause Davis to direct the browser to "/blah.html%3Ffoo=bar?foo=bar" instead of "/blah.html?foo=bar".

olivernn commented 12 years ago

Thanks for reporting this. Just to confirm, this was not present in version 0.9.0? It looks like I introduced a regression in the latest version, I'll take a look.

agildehaus commented 12 years ago

I believe the problem was present in 0.9.0.

iainxt commented 12 years ago

I am also having this issue in 0.8.1

It stems from this code

        delegateToServer: function () {
            window.location.pathname = self.attr('href')
        },

It works if you use

        window.location= self.attr('href')

I have also added some code like originCheck named targetCheck that for A checks the target attribute, if its not null (i.e. _blank) it exits and lets the browser handle it. I was finding it was not opening in a new tab.

var targetChecks = {
    A: function (elem) {
        return elem.target != null && elem.target != '' && typeof(elem.target) != 'undefined';
    }
}

var differentTarget = function (elem) {
    if (!targetChecks[elem.nodeName.toUpperCase()]) return true // the elem is neither a link or a form
    return targetChecks[elem.nodeName.toUpperCase()](elem)
}
olivernn commented 12 years ago

Thanks for reporting this, I have pushed a new version (0.9.3) which includes a fix for this issue

ostronom commented 11 years ago

In 0.9.5 there is no fix for this?

https://github.com/olivernn/davis.js/blob/v0.9.5/lib/davis.listener.js

ostronom commented 11 years ago

Because i'm getting no route found for routes with ?params, but the same route without ?params works fine.