choo icon indicating copy to clipboard operation
choo copied to clipboard

Router match with and without trailing slash?

Open jondashkyle opened this issue 8 years ago • 6 comments

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.

jondashkyle avatar Oct 23 '17 05:10 jondashkyle

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 .

yoshuawuyts avatar Oct 23 '17 06:10 yoshuawuyts

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 avatar Oct 23 '17 14:10 tornqvist

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

yoshuawuyts avatar Oct 23 '17 19:10 yoshuawuyts

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 avatar Oct 24 '17 05:10 tornqvist

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

yoshuawuyts avatar Oct 30 '17 12:10 yoshuawuyts

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.

tornqvist avatar Oct 30 '17 13:10 tornqvist