Catch-all or error routes in Sammy.js
Is it possible to define a catch-all route or an error route in Sammy.js? I know I can bind to 'error' but if no route matches that does not seem to be trigger开发者_如何学Pythoned.
Thanks!
You should override the notFound
function.
Like this:
var app = $.sammy('#app', function() {
this.notFound = function(){
// do something
}
});
This is recommended by the author of Sammy.
According to the documentation for Sammy routes,
Paths can be defined as strings or regular expressions.
As such, it should be possible to create a route like this, at the end of your routes, that is a catch-all:
get(/.*/, function() {
...
});
精彩评论