choo
choo copied to clipboard
Router match with and without trailing slash?
Hey all, ran into a funny one tonight. What are thoughts on matching the router against routes both with and without trailing slashes? For instance, if I add a route like this:
app.route('/about, view)
… should I expect it to work when navigating to both /about and /about/? Currently the latter does not. Open to thoughts! I think it’d be useful.
Makes sense to me! I think we were thinking of rewriting the router anyway to allow for bundle splitting, so this is quite the useful addition ^_^
On Mon, Oct 23, 2017, 07:04 Jon-Kyle [email protected] wrote:
Hey all, ran into a funny one tonight. What are thoughts on matching the router against routes both with and without trailing slashes? For instance, if I add a route like this:
app.route('/about, view)
… should I expect it to work when navigating to both /about and /about/? Currently the latter does not. Open to thoughts! I think it’d be useful.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/choojs/choo/issues/590, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWleiraZ6Flgq8YKUGrFdS7Y99l77Pxks5svB5WgaJpZM4QCTCG .
Great to hear that you're working on a new version of the router, @yoshuawuyts. I was just about to make a PR implementing path-to-regexp (which has an option for strict mode to ignore trailing slash or not), though my motivation was to get optional parameters. Maybe that would be a candidate for the rewrite?
@tornqvist a PR to to nanorouter would be great!path-to-regexp is too much code, and not JavaScript either, so it wouldn't be a good fit for our poject.
What do you mean it’s not JavaScript? The size concern does make sense though, I’ll see what I can come up with.
@tornqvist oh, it's TypeScript if I read it right. If possible it'd be nice to keep all our deps in basic JS without compile steps; that way everyone can read it, and everyone can tweak it. Does that make sense?
Def makes sense but the main export is plain old ES4 (with super expressive JSDoc). Though their tests are in TypeScript and they have some type definition files in their repo. But so does choo. Either way, I tend to agree that almost 400 LOC just to get some regex magic in routes can be considered overkill for a 4kb framework.