I have a router setup like so:
var AppRouter = Backbone.Router.extend({
routes: {
"/agents/:id": "getAgent",
"/orders/:id": "getOrders",
"/users/:id": "getUsers",
'*path': 'defaultRoute'
},
getAgent: function(id) {
ticketList.url = "/index.php/tickets/viewJSON/a"+id;
},
getOrders: function(id) {
ticketList.url = "/index.php/tickets/viewJSON/o"+id;
},
getUsers: function(id) {
ticketList.url = "/index.php/tickets/viewJSON/u"+id;
},
defaultRoute: function() {
//(here needs to be the code)
}
});
I’m using codeigniter, so when I visit /index.php/agents/view/1103 I need to force the ticketList.url to be /index.php/tickets/viewJSON/a1103 – the a is taken from /agent/ (this will change between user, agent and order, u,a and o respectively, and then the ID taken from whatever trails the view section of the URL.
Whats the best way to get the default route to take these paramaters from the URL? Literally splitting document.URL?
It would be easier to read if you consolidated your three custom routes to one custom route, instead of putting them all in the default.
But note that this will match a lot of different URLs, possibly more than you really want. It might be a better idea to have separate routes for each resource, and just map them all the the same function.