reload or change page before Sammy could get near it. Is this HTML5
browser load new pages. Hence, I put in quite a bit of work to unify
Sammy and a single page. Can it really do this?
On Mar 22, 8:19 am, Aaron Quint <
aa...@quirkey.com> wrote:
> Hey All
>
> Heres an oft-requested and oft-put off feature thats finally working and is actually (once used) very exciting. Glenn's questions and prodding have pushed me to share it with the community. You can check out the `non-hash` branch and play with it at home:
>
> Commits:
https://github.com/quirkey/sammy/commits/non-hash
> Compare:
https://github.com/quirkey/sammy/compare/master...non-hash
>
> A little while ago a PushLocationProxy made it into master. It had basic support for pushState (aka HTML5 History), but it didnt really work well because of some unrelated Sammy internals surrounding how we handle paths and 'locations'. It did, however, give me a lot of really great ideas and provided the foundation for something I've wanted to do for a while now, namely figure out a way to transparently handle either '/' urls (and pushState) and '#/' style URLs (hashchange). I _think_ I've got a pretty solid first pass going.
>
> Heres a demo to play with (best viewed in the latest and greatest Chrome, FF4, or Safari 5)
>
>
http://pushstate.ixxr.net/
>
> The cool thing about that above, is its just a couchapp (a soca app to be exact) and it transparently responds to either full urls or hashes. With some simple rewrite rules and a vhost, it works the same when you reload the app as when you left off even with full paths.
>
> The big change that powers this is the new DefaultLocationProxy (was the HashLocationProxy). This allows Sammy to handle both full paths and hash based paths. If you click a link within Sammy's element, it checks to see if that link will match a route and if so, pushes the state (if available) and triggers the route.
>
> There are a couple of backwards incompatible changes here, the biggest being that if you're checking `path` in an EventContext (i.e. in the body of a route or event) its now the full path (starting at / instead of at #). This doesn't really matter if you're just using basic routing, but if you ever call `this.path` explicitly (like in a before filter) you might have to make some changes.
>
> If you want to try it out (beyond the example above), pull down the latest version from the `non-hash` branch. I suggest defining your routes like
>
> this.get('/push/:id', ...
>
> instead of
>
> this.get('#/push/:id', ...
>
> as the former will match against both the hash and non-hash version.
>
> Also, as you can see in the example, if you do redirect('push/one') or link without the prefixed '/' Sammy will use pushState where available then fallback to using #/.
>
> Have fun!
> --AQ
>
> --------------------------------