Is it possible to have optional parameters in a Backbone.js route?
e.g this:
routes:
\"search/[:query]\": \"searchIndex\"
instead of:
What about using the *splat
:
routes
router.routes
The routes hash maps URLs with parameters to functions on your router, similar to the View's events hash. Routes can contain parameter parts,
:param
, which match a single URL component between slashes; and splat parts*splat
, which can match any number of URL components.For example, a route of
"search/:query/p:page"
will match a fragment of#search/obama/p2
, passing"obama"
and"2"
to the action. A route of"file/*path"
will match#file/nested/folder/file.txt
, passing"nested/folder/file.txt"
to the action.