| Page 1 of 1 | [ 7 posts ] |
|
I'm in the process of building a web page using Y.App and 3.6.0pr2. I'm modeling after the GitHub Contributors example. For my app, I'm setting the root to be something like this:
Code: new Y.MyApp({ root: "/my/custom/root" }).render(); I then have a path set up as follows: Code: routes: { values: [ { path: "/:id/*", callback: "handleId" } ] } If I define handleId as follows: Code: handleId: function (req, res, next) { alert(req.params.id); } With serverRouting = undefined and viewing Firefox, using the URL http://localhost/my/custom/route/1 will alert "1". However, when I view the URL http://localhost/my/custom/route#/1/ in IE or with serverRouting = false (so no HTML5 functionality is used), the alert will be "my". It's as if the params logic isn't using the root attribute when it's not HTML 5. Am I doing something wrong? |
|
Hmm, can you provide a working example of this behavior so I can help debug? I was unable to reproduce this behavior using the following:
App Test RootClick here to see the revision history on this Gist. |
|
I think the issue has to do with the use of the ending "/". Locally, I've set it up so both of the following paths will return your sample page:
http://localhost/customroot/AppTest http://localhost/customroot/AppTest/ and set root as: Code: root: '/customroot/AppTest/' I'm using ASP.NET MVC, and both of those routes will match to the same action. If I visit this URL: http://localhost/customroot/AppTest/#/1/ it will correctly output "1". If I visit this URL: http://localhost/customroot/AppTest#/1/ (notice a / is missing) it will output "customroot". So clearly, the trailing "/" is causing a difference. This is fine, but I would prefer that the latter URL work. So, to fix this, I adjusted the root to be: Code: root: '/customroot/AppTest' (removed the final /)However, this does not fix the problem, as after doing so, the output for the second URL is still "customroot". I also attempted to change the route path from '/:id/*' to ':id/*' and that just outputs blank. |
|
Okay, so I see what's going on and why you're ending up in this situation. I recently changed how the hash-based URLs work as described here:
http://yuilibrary.com/projects/yui3/ticket/2532318 What's happening is the hash-path is resolved against the URL's path, i.e. it's resolving "1/" against "/customroot/AppTest", which leads to: "/customroot/1/". From there the `root` is suppose to be removed from the URL, but in this case, since the root no longer exists in the resolved path, it's a no-op. Could you please file a bug for this issue where hash-based URLs are not routing properly when the root does not end with a trailing slash? |
|
Ticket created: http://yuilibrary.com/projects/yui3/ticket/2532486
If anyone else runs into this issue, I was able to workaround it by having my server logic redirect to the URL and append the ending "/" if it was missing. I then used a root that ended in a "/". |
|
This is why we do preview releases. I will make sure to have this fixed for 3.6.0 final. Thanks for taking the time to dig into this one and filing the ticket, I really appreciate it.
|
|
Okay here's the pattern I'm going to use for hash-based paths and "spreading" over the `location`'s `pathname` and `hash` parts:
Example Router SetupsClick here to see the revision history on this Gist.Notice in the last three examples the `root` is part of the hash, this is because the `root` does not equal the current URL's `pathname` (the full path) or the URL's path-root (the `pathname` ending at the last slash). The reason the URL's path-root is also checked is to deal with a common case where the URL's `pathname` is "/app/index.html" and the router's `root` is "/app/". Here's the diff of the changes I'm going to make which will solve this issue: Router DiffClick here to see the revision history on this Gist. |
| Page 1 of 1 | [ 7 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group