azicchetti/jquerymobile-router

Event handler gets invoked twice on back button

Closed this issue · 4 comments

I working on an app using jQuery v1.7.1, , jQM v1.1.0 RC1, require and backbone.
In the index.html I have for each page some html fragments like this:

  <div id="category-content" data-role="content"></div>    

and in the router for that page I have:

"#category([?].*)?" : { handler: 'categoryHandler', events: 'bs'},

In the categoryHandler I fetch some data to populate a listview. This seems to work as I thought it should be right routing to the page with the listview, but when clicking the page or browser back button from there the categoryHandler gets invoked twice.

What do I miss?

Hi,
thank you for the bug report. This was already reported by raldred a couple of weeks ago and in this issue thread there's a temporary solution:

#31

I'm trying to support the stable jquery mobile version with the current router release, so I'm holding back the patch until things are more clear with the new 1.1.0 version.

They've changed a lot and it seems that there's even a native support for page arguments in the hash part of the url (#localpage?foo=bar) within jquery mobile itself, although it's still a bit incomplete.
When the 1.1.0rc2 rolls out (and it's due in a few days) I'll probably dig into this problem a bit more and release a -rc2 compatible version of the router.

Oh .., ok. Looking forward to the next patch.

And thanks for this great plugin!

Hi,
I've pushed a fix to support jqm 1.1.0rc2.

It turns out that the 'native' support for hash parameters is a side effect of a jquery selector used in the loadPage() function of jQM.
Since I'm scared by this, I'm overriding this behaviour with a code snippet that I think is more safe and sound.

Hopefully the handler won't be called twice with the latest fix.

Hi azicchetti,

I can confirm that your fix prevents the handler to be called twice in my use case.

Thanks a lot.