Is it possible to have optional parameters in a Backbone.js route?
e.g this:
routes:
"search/[:query]": "searchIndex"
instead of:
routes:
"search/": "searchIndex"
"search/:query": "searchIndex"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As of Backbone 0.9.9, you can add optional paramaters with parentheses.
For example in your routes object you can define an optional route part like this:
Now the url path will match
/#organizeand routes like/#organize/create.Keep in mind that if you need routes like
/#organize/(with a trailing slash) to be recognized, you can do: