Catch all or bugs in Sammy.js

Is it possible to define a catch-all route or an error route in Sammy.js? I know that I can be attached to an "error", but if the route does not match, which does not seem to work.

Thanks!

+8
javascript
source share
2 answers

According to the documentation for Sammy routes ,

Paths can be defined as strings or regular expressions.

Thus, at the end of your routes it should be possible to create a route that is common to all:

get(/.*/, function() { ... }); 
+9
source share

You must override the notFound function.

Like this:

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

This is recommended by author Sammy.

+23
source share

Source: https://habr.com/ru/post/650321/


All Articles