baseprime / grapnel

The smallest JavaScript router with named parameters, HTML5 pushState, and middleware support
http://grapnel.js.org
468 stars 40 forks source link

Ignore subsequent routes after .preventDefault() #14

Closed cecchi closed 9 years ago

cecchi commented 10 years ago

New to Grapnel but impressed with the functionality so far. I've added the ability to do something like this, which some other routing libraries support in varying formats and can be very useful:

var router = new Grapnel();

router.get('api/*', function(req, e) {
    if(!isAuthorized) e.preventDefault();
});

router.get('api/secret', function(req) {
    // Authorized users only!
});

I'm undecided on whether the use of preventDefault is inappropriate for this behavior, I'm happy to change it to a new method or simply return false if that would be clearer. return false would more likely be a breaking change.