fridays / next-routes

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

params mismatch between client/server #10

Closed scf4 closed 7 years ago

scf4 commented 7 years ago

I have the route /post/:slug-:id. It works fine on the client, but when SSRing I get a 500 error if the slug has a hyphen in it. I think it interprets the :id as the first thing after the first hyphen.

fridays commented 7 years ago

Hey that's right, the regex stops at the first hyphen and assigns the rest to id. You can define the route like this to avoid it:

/post/:slug-:id([^-]+)

It uses path-to-regexp to match the routes, check it out for more examples. The reason that it works on the client is that the URL is only a decoration there and is not used for matching params.