0

I have the route 'availability/exceptions' which routes to the function availabilityExceptions and which works fine:

    return Backbone.Marionette.AppRouter.extend({
        appRoutes: {
            'availability/exceptions(/:key1)(/:value1)': 'availabilityExceptions',
        }
        ...

I want to be able to route to that function no matter what follows 'availability/exceptions'. E.g. 'availability/exceptions/some_key/some_val', 'availability/exceptions/some_key/some_val/some_key2/some_val2', 'availability/exceptions/some_key/some_val/some_key2/some_val2/some_key3/some_val3' etc should all go to availabilityExceptions and passing through whatever comes after 'availability/exceptions'. Is this possible?

Mark
  • 4,428
  • 14
  • 60
  • 116

1 Answers1

1

You can use a *splat to accomplish what you're asking. It consists of a asterisk followed by a string. So you would set up your route as follows:

appRoutes: {
  'availability/exceptions(/*string)': 'availabilityExceptions',
}

and this would match any number of URL components that follow 'exceptions'. 'string' can be replaced with any other text of your choice. The part of the URL after exceptions gets passed as a parameter to your function.

So if you navigated to availability/exceptions/some_key/some_val/some_key2/some_val2, your function can handle it as follows:

availabilityExceptions: function(enteredURL) {
//enteredURL equals "some_key/some_val/some_key2/some_val2"
}
zdestiny
  • 542
  • 3
  • 10