fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Make a route that will work with ending slash or not? #24

Closed ghost closed 7 years ago

ghost commented 7 years ago

This might be more related path-to-regexp, but figured I'd start here.

I'd like to create a route definition that works with and without the ending slash. For example:

routes.add('myEntity', '/entity/:id\/*', 'entityPage');

What I want here is for the router to accept both of the following:

http://localhost:3000/entity/foo

and

http://localhost:3000/entity/foo/

Where foo is mapped to the id parameter.

Is this possible? Is this a question for path-to-regexp instead?

It seems path-to-regexp does this by default and it doesn't look like next-routes is overriding this default. So maybe this is a bug? Should the following routes, be default, both resolve to the same page:

http://localhost:3000/entity/foo http://localhost:3000/entity/foo/

fridays commented 7 years ago

Yes this is only related to path-to-regexp and should work by default. Maybe it conflicts with the last parameter, then it could help to use a regular expression for the path definition.

ghost commented 7 years ago

I think it's actually related to the other issue I opened. next-routes wasn't fully running because of my own ignorance (though, oddly it looked like it was). Once I got that sorted, this issue also resolved. Thanks. Great package BTW.