Is it possible to have optional parameters in a Backbone.js route?
e.g this:
routes:
\"search/[:query]\": \"searchIndex\"
instead of:
Probably the most easiest way is just declare more than one route, one with the extra arg,one without:
routes:{
"authProxy/:hash": "authProxy",
"authProxy/:hash/:url": "authProxy"
}
then just check for them in your method:
authProxy: function(hash, url){
if (url){
// Hash and URL.
}else{
// Just hash.
}
}
Note that I like this much better than the other two answers because it's very easy for another developer to understand what's going on.