olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Router's before and after methods are not scoped. #54

Closed ali-sattari closed 11 years ago

ali-sattari commented 11 years ago

Scope isn't applied to before and after methods in Davis.Router, making it confusing for path specific calls.

This works:

app = Davis(function(){
    this.scope('/myapp');

    this.before('/myapp', function(req){
        console.log('before /', req);
    });
    this.get('/', function(req){
        console.log('get /', req);
    });
});

While this should work:

app = Davis(function(){
    this.scope('/myapp');

    this.before('/', function(req){
        console.log('before /', req);
    });
    this.get('/', function(req){
        console.log('get /', req);
    });
});

The issue can be solved by changing filter method of Davis.Router to add scope to the path when there is 2 arguments.

olivernn commented 11 years ago

Good catch, I've just pushed a new version (0.9.4) of the library with a fix for this, thanks.