azicchetti / jquerymobile-router

A router/controller for jquery mobile. Also adds support for client-side parameters in the hash part of the url. The routes handles regexp based routes. This plugin can be used alone or (better) with Backbone.js or Spine.js, because it's originally meant to replace their router with something integrated with jQM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Navigating back to a previously rendered page does not fire an event

blowsie opened this issue · comments

When navigating from mysite.com/index.html#page-name to mysite.com/index.html#page-name?info the routers are fired, however when navigating back, using the browser back button no events are fired.

Is the intended outcome?
Is there a work around?

Only all of my pages are templated and I have no way of re-rendering them when navigating backwards through the site.

my, bad, i was using the wrong event , i needed to use the beforechange (bC) event

Hi @blowsie ,
there's a test file covering this scenario under examples: testBackButton.html

As far as I know, it should work with jquery mobile 1.1.0 and jquery 1.7.1 / 1.6.4.

Could you please explain whether your case differs from that one, possibly providing some source code?

Thank you

Uhm, using bC is not recommended (it should be used only to do very particular things in jquery mobile), if you need to resort to that event there's probably something wrong.

Page transitions triggered by the back button can be handled with pagebeforeshow and pageshow

When navigating from mysite.com/index.html#page-name to mysite.com/index.html#page-name?info there is a page transition, but when you use the back button there is no transition, why is this?

My case differs from the example testBackButton.html as follows.

testBackButton.html navigates from testBackButton.html#page to testBackButton.html#page2,

my example navigates from mysite.com/index.html#page-name to mysite.com/index.html#page-name?info

notice how on my version the hash remains the same but im adding a parameter / search ?info on my url, it is when navigating backwards to#building-info that the problem occurs


I have uploaded a file to demonstrate the issue.
http://www.touch-stone.net/tests/temp/jqm-event-bug/index.html

Drill all the way down to the last page and then navigate backwards.

I see, when the application transitions back from #something?param to #something, the allowSamePageTransition is not set by the router and jquery mobile doesn't fire any event.

Replace the following line in the router

if ( u.hash.indexOf("?") !== -1 ) {

with

if (    u.hash.indexOf("?") !== -1 ||
        (u.hash.length>0 && previousUrl!==null && previousUrl.hash.indexOf(u.hash+"?")!==-1)
) {

It's a very specific patch so it shouldn't compromise the router stability.
However, I have to do some more tests before officially pushing it to the git.

Thank you very much for finding this obscure bug!