You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conventionally when you give a router a set of urls to match it's a case of first one wins. I am assigning handlers to the following routes:
users/me
users/:id
In the case of backbone requesting users/me the users/:id route is winning.
Reversing the handler definitions does the trick but in my experience the first matched route is usually supposed to handle the request.
The text was updated successfully, but these errors were encountered:
This behaviour of later routes overriding earlier ones is by design and meant to mimic Backbone.Router's behaviour where, according to the docs
Routes added later may override previously declared routes.
It's done this way in an attempt to introduce as little convention as possible - where that is feasible. Let me know if you think there's reason to do it the other way around.
I'd like my 'fauxServer' to be as close to the actual server as possible. All route matching libraries I've used in the past have done it 'first match wins' style, and so I had assumed this was the convention.
I think that line from the Backbone docs refers to overriding an existing route with a new handler, rather than the new route winning due to it being declared later, but I haven't tested this.
It's perhaps just a bit more of a usual pattern whether writing a case statement or an if, else if, or a loop that breaks or a functional loop that returns early...they all tend to pick the first match. This also helps performance a bit.
Also it might be useful to know... I'm not actually using backbone's router in my later projects as it doesn't really play a part in synchronising my Models/collections to a Restful server.
Hi, love the plugin!
Conventionally when you give a router a set of urls to match it's a case of first one wins. I am assigning handlers to the following routes:
users/me
users/:id
In the case of backbone requesting users/me the users/:id route is winning.
Reversing the handler definitions does the trick but in my experience the first matched route is usually supposed to handle the request.
The text was updated successfully, but these errors were encountered: