1

How can i match route if the url contains somewhere a parameter with a specified action ? Like myaction/someparam1/someparam2/PleaseMatchMeIfYourFindMe/someparam3

mu is too short
  • 426,620
  • 70
  • 833
  • 800
MR.ABC
  • 4,712
  • 13
  • 44
  • 88

2 Answers2

3

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/

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
mu is too short
  • 426,620
  • 70
  • 833
  • 800
-1

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
    }
HungryCoder
  • 7,506
  • 1
  • 38
  • 51
  • i know the standard example pattern. I don't know what is not clear. Match a route if the url contains a specified string after my action. – MR.ABC Mar 19 '13 at 05:30