Reputation: 4862
How can i match route if the url contains somewhere a parameter with a specified action ? Like myaction/someparam1/someparam2/PleaseMatchMeIfYourFindMe/someparam3
Upvotes: 1
Views: 2548
Reputation: 434615
Backbone's routes
objects don't offer quite that level of flexibility. However, you can add routing regexes manually using the route
method:
route
router.route(route, name, [callback])
Manually create a route for the router, The
route
argument may be a routing string or regular expression.
So you can do things like this in your router:
initialize: function() {
this.route(/^myaction\/.*PleaseMatchMeIfYourFindMe/, 'handler_method');
}
You will of course have to adjust the regex to match your real requirements. If you want to get parts of the regex as arguments to your handler then add capture groups as needed.
Demo: http://jsfiddle.net/ambiguous/pFXr6/
Upvotes: 3
Reputation: 7616
Your question is not clear. You can use parameters in your route definition like this:
var Route = Backbone.Router.extend({
routes: {
'myaction/:param1/:param2/:param3/:param4': 'myActionCallback',
},
myActionCallback: function(param1, param2, param3, param){
//your magic starts here
}
Upvotes: -1