I'm trying to get GitHub-esque route matching through Backbone. This means that hits to /:userName
should get caught last, after every other route has been checked. In my current setup my unit
route gets triggered on all calls, is there a way to make it behave properly? Many thanks!
'use strict';
/**
* Module dependencies
*/
var course = require('./views/course');
var unit = require('./views/unit');
/**
* Routes
*/
var Router = Backbone.Router.extend({
routes: {
'(/)': 'course',
'/:user/:course/:unit(/)': 'unit'
},
course: function() {
course();
},
unit: function() {
unit();
}
});
/**
* Init router
*/
var router = new Router();
/**
* Options
*/
Backbone.history.start({
pushState: true
});
It appears that if you make routes that start with a "/something", Backbone interprets them as "//something". So the solution was to remove all prepending slashes, now it works just fine.