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

adding multiple handlers for the same path drops the first handler #23

Open
neonstalwart opened this issue Jul 17, 2014 · 2 comments
Open

Comments

@neonstalwart
Copy link

should it be possible to add more than one handler for the same path? is that reasonable?

@Raynos
Copy link
Collaborator

Raynos commented Jul 17, 2014

@neonstalwart that's not currently possible with strings.

You can add a handler for .addRoute('/foo*') and .addRoute('/foo/bar') then use the .next() feature to get both matches and invoke them.

Because the implementation is based on a routeMap that is keyed on the route expression you can't do this.

However on trick you can do is create two regular expression objects that serialize two different strings but are the same paths. That is a dirty work around though.

What's the actual use case for multiple handlers per path ?

@neonstalwart
Copy link
Author

i've written a router that builds on top of this lib to add some more features - e.g. you can remove a route or you can generate an href from a route with an object to help fill in the params, etc. my use case only came about for some tests i'm writing for that router. i was testing the remove capability by adding 2 handlers for the same route, removing one of them and then testing that only one of them gets called.

i could try to make up some really compelling scenarios where having 2 handlers or removing a route might be useful but in all honesty i haven't had a need for either of those yet so i'm not concerned about trying to support a feature that i don't even use. this is why i opened this issue as a question - if it's not something worth doing, i'm ok with that.

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

No branches or pull requests

2 participants