Skip to content
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

Route matching order #14

Open
lukesargeant opened this issue Apr 8, 2014 · 3 comments
Open

Route matching order #14

lukesargeant opened this issue Apr 8, 2014 · 3 comments
Labels

Comments

@lukesargeant
Copy link

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.

@biril
Copy link
Owner

biril commented Apr 9, 2014

Hi @lukesargeant , glad it's working out for you.

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.

@biril biril added the question label Apr 9, 2014
@lukesargeant
Copy link
Author

Hi @biril ,

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.

@lukesargeant
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants