sammy
sammy copied to clipboard
Chrome 404 bug - after first run (get '#/'), if you go to a new route (eg get '#/inbox') then hit back button, app doesn't re-initialise and logs 404
Hey,
Been playing around with Sammy in Chrome/Mac and am hugely impressed with its capabilities.
I've found a bug though that doesn't seem to happen in Firefox, but does seem to affect all the available Sammy demos in Chrome. Haven't been able to find a workaround so asking here!
If you go to a sammy app's front page, e.g.
http://nettuts.s3.amazonaws.com/763_sammyJSIntro/demo/index.html
The app fires up (eg "index.html#/inbox" ) - then, if you click to visit one of the routes, eg "index.html#/compose", that loads fine too.
Now if you hit the back button, the app doesn't fire up, and nothing happens, but the URL updates to simply "index.html" (with no sammy route defined) - the console also logs a 404, eg:
[Wed Jan 19 2011 12:55:40 GMT+0800 (HKT)] runRoute get
[Wed Jan 19 2011 12:55:40 GMT+0800 (HKT)] 404 Not Found get Error: 404 Not Found get
I've been trying for a few hours and searched up every topic on the subject but haven't found a solution to this. It seems like a fairly major issue, unless I'm being stupid!
Would really appreciate anybody's help on this. Thanks.
Wow, 20 minutes later I think I've found a/the solution.
Placed after all other routes, this 'get' rule should catch all empty requests and force the app to start up.
I also found and included a method to catch all requests that weren't matched to routes and generate a custom 404. Though I'd throw that in as well, but feel free to ignore that second part.
Please let me know if this is the right/wrong way to go about it and feel free to close this issue if so!
Thanks
// Do this when no route defined:
this.get('', function(context) {
// No route defined, set location to '#/' to trigger app automatically:
document.location.hash = '/';
});
// Catch-all for 404 errors:
this.get(/.*/, function() {
console.log('404... come on, really?');
});
I have also found the same problem with Chrome, works very well in Firefox though. Also in chrome, on a backup any content in the element tab of developer tools that has been generated using client side templating is not shown, even if the content is on the page!