-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routes with named params #22
Comments
@revathskumar : Subroutes behave exactly the same as regular routes, including the way you set up a response function. Such as: showTransaction: function(country) {
// do something with "country" variable
} The only difference is that all of the routes in a subroute are automatically prepended with whatever var mySubRouteInstance = new VacationDestinationRouter("vacations"); Then your routes above would match URLs like Hope this helps. If you are still having issues, please attach some code and a description of what you're trying to do so I can understand the context. |
I don't have a prefix like vacation. My URL looks like
Is there any that I can split transaction and report to different modules and subroutes? |
All subroutes require a prefix, but the prefix itself can contain parameterized route sections. For instance, let's say you define a subroute like this: var TransactionRoute = Backbone.SubRoute.extend({
routes: {
"" : "handleDefault",
"search" : "handleSearch",
"view/:transactionId" : "handleViewTransaction"
},
handleDefault: function(country) {
alert("default - country: " + country);
},
handleSearch: function(country) {
alert("search - country" + country);
},
handleViewTransaction: function(country, transactionId) {
alert("view transaction - country: " + country + " id: " + transactionId);
}
}); You can then create an instance of the subroute like this: var transactionRoute = new TransactionRoute(":country/transaction"); All of the routes defined in your subroute will be created by concatenating the route prefix (which contains a parameterized section) with the routes in your subroute. So if you navigate to You could create a similar SubRouteExtension called ReportRoute, with similar handlers, and instantiate it like so: var reportRoute = new ReportRoute(":country/report"); Note that this wasn't really how I intended subroutes to work, since the above subroute definitions require knowledge about how a particular instance of itself is instantiated (that there will be a country param in the prefix) but it works nonetheless. Generally I prefer the URL to be read from least-specific to most-specific, from left-to-right, with the module name that defines the subroute appearing first. So ideally the URL would be something like Let me know if this works for you... EDIT: Clarified some language in last paragraph. |
Experiencing the same issue. It is caused by the following:
I submitted a pull request to hopefully solve the issue |
Thanks for the PR, Chris! I won't be able to look at this until later in the week. In the meantime, could you also please add a unit test to the PR that fails without your fix and passes with it? (Also verifying that the fix does not break any existing unit tests?) This will help me merge it much more quickly. On Jun 30, 2013, at 1:16 AM, Chris notifications@github.com wrote:
|
I have added a unit test that fails with your current code and functions correctly with mine. Also, all of your previous tests pass with the changes. The changes only effect initial loading of a URL |
How can I use subroutes with named params
if I am using subroutes, how can I get the value of :country in my action?
The text was updated successfully, but these errors were encountered: