fridays / next-routes

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

Next-routes two components with same main route #266

Closed MontoyaAndres closed 5 years ago

MontoyaAndres commented 5 years ago

Hi, I want to have this configuration in the routes file with next-routes:

module.exports = routes()
.add({ name: "perfil", pattern: "/perfil/:id", page: "perfil" })
.add({ name: "edit", pattern: "/perfil/:id/edit", page: "edit" })

One component called "edit" that has the route /perfil/:id/edit and other for "perfil" which is /perfil/:id.

But that does not work, the component "perfil" gives me the route /perfil/:id and the component "edit" gives me /edit. How can i resolve this?

Thanks!

juliankoehn commented 5 years ago

same issue:

    .add({name: 'category', pattern: '/:id', page: 'category'})
    .add({name: 'post', pattern: '/:category/:slug+', page: 'blog'});
AugustinLF commented 5 years ago

You should put the most specific first. Because here /product/123 matches /:id, where id is product/123.

MontoyaAndres commented 5 years ago

Oh, same does not matter... I use now 2.0 and I don't use the server.js file

juliankoehn commented 5 years ago

@AugustinLF got the same issue with this change.

Works fine, at least for the current needs. Maybe i have to implement somekind of URLResolver on the API side.

.add({name: 'category', pattern: '/:id+', page: 'content'})

image

MontoyaAndres commented 5 years ago

@juliankoehn why not just create the typical way to create routes in nextjs? In the server.js you put those routes and it's like if you were implementing a rest API...

juliankoehn commented 5 years ago

@MontoyaAndres like that? https://zeit.co/guides/custom-next-js-server-to-routes#step-3:-defining-routes-configuration

Thank's!


Well that's usefull if we would host at @Now if i'm not misunderstanding the docs

MontoyaAndres commented 5 years ago

@juliankoehn the example you sent is using now, which is great, I use it. But what I was talking about is this https://github.com/zeit/next.js/blob/canary/packages/next/README.md#custom-server-and-routing

juliankoehn commented 5 years ago

@MontoyaAndres it's nearly doing the same as i did within the getInitialProps, i'll keep it at mind and maybe swap over in point of performance.

Thanks for sharing :-) 👍

MontoyaAndres commented 5 years ago

I'm going to close this issue because the author never responded.