routes.js icon indicating copy to clipboard operation
routes.js copied to clipboard

adding multiple handlers for the same path drops the first handler

Open neonstalwart opened this issue 10 years ago • 2 comments

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

neonstalwart avatar Jul 17 '14 19:07 neonstalwart

@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 ?

Raynos avatar Jul 17 '14 23:07 Raynos

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.

neonstalwart avatar Jul 21 '14 14:07 neonstalwart