-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Dynamic Page Generation & Page Refresh #5085
Comments
Hi, |
You said you followed the instructions on this page, but I don't see the issue you mentioned when I test our working example. We need a test page to see if this is a bug or a problem with your code. See Contributing Guidelines for a link to our JS Bin template. |
Hi, reveals the problem. |
If I click that link I get to see the category overview page ("Select a Category Below"), as expected. I am not sure what you mean by #home page in this case. Also, I don't get a "Uncaught Error: Syntax error, unrecognized expression:" error as you mentioned and the |
Uhm, no, that's not the expected behavior. If we have a multipage template, with two pages (#onw and #two), it's possible to deep link the second page and make it work as a straight url. Similarly, we need a way to do the same thing with parameters that are appended to the hash, such as #two?foo=bar or #category-items?category=animals. Until 1.1.1 we could bind to the pagebeforechange event, parse the data.toPage property and do some "magic" (e.preventDefault, trigger a programmatic changePage to a certain page div, etc). The bug described by @milantopalov is strictly related to #5080. To further prove the point, take the previous example with jQM 1.1.1: vs The same page leads to different results, the first (w/ 1.1.1) being the right one. Hope everything is clear now, it's a kinda diffucult topic ;) |
AFAIK we don't support deep-linking to pages (dynamically generated or otherwise) with query parameters. The reason it worked in 1.1.1 is because an old version of jQuery would accept a faulty selector ("#page2?msg=hello"). Newer versions of jQuery no longer accept such a selector, and, as a result, that which accidentally worked before has now stopped working. Nevertheless, the current behaviour is what's intended. The docs mention two plugins which allow you to pass query parameters between pages (bottom of the docs page). Try those. @johnbender is the authority on this topic. |
Mentioning #4777 because that one also deals with query parameters. |
Hi @gabrielschulhof , I'm aware that jQM won't support query parameters natively, since the previous behavior was more of a bug than an intended feature. But the sample-reuse-page contains a certain pagebeforechange handler technique, which is the basis on which we can develop routing plugins. Unfortunately, with 1.2.0-rc* versions, we don't have the first pagebeforechange with the string url anymore and thus we can't add support for query parameters to deep links (see #5080). |
We'll have to address this in the first point release but we've got some other things to deal with there as well, so it's likely to be released fairly quickly. |
Great, thank you! |
@azicchetti I'm working on this in a branch. I may just end up addressing the original issue but I have to have a chat with @jblas first. |
This will get merged after the release. |
Thank you.
Thank you very much for your help. |
Let me address each in turn:
$.mobile.changePage( "#foo", {samePageTransition: true}); |
Most importantly, thank you for all your help. It makes it much easier to get this right early when application developers participate as you have! |
On number 1 I'd like to change my response :) We've got a lot of code that makes url's absolute for different circumstances (links, forms, etc) and then a fallback in |
I'm going to move the attribute up to the the data object, it doesn't makes sense (and I knew this when I started) as an option value. Thinking about |
I pushed a change that will push our resolution of the absolute url on the data object as the |
Thank you very much for your quick answers, I'm gonna test the patch in the next few hours. In the meanwhile, let me check if I got this right:
I've just another question (even if I don't think that I'll use this trick if data.url works as described above, but it's useful to know anyhow): in previous jQM releases, I was storing a certain property in data.options (during the pagebeforechange event) in order to "mark" the current page transition and be sure that I wasn't processing the same "route" multiple times. Thank you very much for your time! |
I simplified things so that the absolute url will always be provided in both the page loading and page changing events on the data object at To be clear, if $( document ).one( "pagebeforechange", function( event, data ) {
// NOTE! this will be triggered twice but the value will be the same
console.log( data.absUrl );
});
$( document ).one( "pagechange", function( event, data ) {
console.log( data.absUrl );
});
$( document ).one( "pagechangefailed", function( event, data ) {
console.log( data.absUrl );
});
$.mobile.changePage( "#bar?foo=baz" ); As to your last question the |
Hi there. I tried the patch above and it worked great for reenabling the ability to enter a site to a dynamic page ie: #animals?category=cats However now when browsing the site and clicking a url ie: href="#animals?category=cats" the site goes to the page but the history hash ends up as #animals . This messes up the history and the ability to bookmark a page. my "ugly fix" is to keep the old convertUrlToDataUrl and create a convertUrlToDataUrlNew (patch version) only for use by initializePage process. Hope this helps someone and hopefully this is all fixed up soon in a point release. Cheers |
The above path fixes the problem (Convert url params to data params) but it does not work on refresh as it used to be in the past (jqm 1.1). So when you have #animals?category=cats it converts category to data.param and url becomes #animals but on refresh it does not as it used to be. Does any one have a fix for that? |
This is a first pass at solving the issue. We're attempting to allow linking to embedded pages with extra information attached. If you guys would like to see the params preserved, please open a separate issue with the feature request and make sure to reference this one. |
Trying to generate a dynamic page.
I've followed the instructions (http://goo.gl/e9RPr) and it works just fine when flicking between pages.
The problem appears when user lands on the page containing some parameters (or refreshes it; i.e. not by clicking a link within the app, but say from an external website)...
e.g. if users was to land on this page
http://www.domain.com/jqueryapp#page?msg=hello
not only would "pagebeforechange" event not fire, but JS would break - console would display:
"Uncaught Error: Syntax error, unrecognized expression: #page2?msg=hello"
Is there a way around this?
Cheers!
The text was updated successfully, but these errors were encountered: