jQuery Mobile changePage in pagebeforeshow Flicker

jQuery Mobile changePage in pagebeforeshow Flicker

In several of my jQuery Mobile pages, I need to ensure that certain variables are set before allowing the page to show. As such, I check for these variables in the pagebeforeshow event and if they are not present or correct, I call the $.mobile.changePage(...) inside the pagebeforeshow event and then immediately return.

In jQuery Mobile 1.2.1 this seemed to work perfectly. However, now that I'm using jQuery Mobile 1.3.1 I've noticed an odd rendering issue. Now when I call the changePage inside the pagebeforeshow event, it causes jQuery Mobile to transition to the page I requested, then back to the original page, firing thepageshow event, and then finally transitions back to the page I did the changePage to.

While not a major issue, it is a inconvenience and causes unnecessary transitions. Has anyone else encountered this issue and if so, have you been able to prevent the unnecessary transitions and event firing? This is mostly used to ensure that if a user refreshes on a jQM page that needs data from another page, it can safely transition to the needed page. Thanks!

Example Code:

$('#ConditionalPage').on('pagebeforeshow', function () { if (!someScopedVariable) { $.mobile.changePage('#RegularPage'); return; } } $('#ConditionalPage').on('pageshow', function () { ... \\ Code that gets fired even though pagebeforeshow called changePage. }