404 Not Found event or Catch-all route #67

Closed
lgomez opened this Issue Dec 20, 2010 · 8 comments

Comments

Projects
None yet
4 participants

lgomez commented Dec 20, 2010

Is there a way for me to set a 404 route or a catch-al route for when none of my defined routes match?

lgomez commented Dec 22, 2010

That worked perfectly.

Did you consider adding a something like '404' as a route instead of requiring an override? Not a big deal. Just curious.

Thanks!

Hey, I'm looking for the same thing myself - had a look through the docs, but still not sure where I need to override notFound().

If you have time, could you please explain how and where to override it? Thanks!!

lgomez commented Jan 18, 2011

Sure, in my case I did something similar to:

var app = $.sammy('#somediv', function() {
  this.get('#/somehash', function(context) {
    // do somethihnng
  });
  this.notFound = function(){
    // do something
  }
});

I hope that helps.

Thanks! Yeah that clears it up. This worked great for me as an example:

    this.notFound = function(){
        this.swap('');
        $("<p>Oops, that couldn't be found</p>").appendTo(this.$element());
    }

Wonder how this impacts SEO - whether these 404s are treated like normal HTML 404s :S

lgomez commented Jan 19, 2011

@josscrowcroft So far I've only used sammy for apps behind a login to avoid dealing with SEO and other issues like that. There are ways to work around them but I prefer to avoid them and keep it simple.

Fair play. Cheers!

I use notFound to trigger a jQuery UI modal, or an internal message. Handy, thx. :-)

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment