gvergnaud / nextjs-dynamic-routes

[Deprecated] Super simple way to create dynamic routes with Next.js
MIT License
140 stars 7 forks source link

Question: Choose the pattern to display in the URL with Link #20

Closed camillegrings closed 5 years ago

camillegrings commented 5 years ago

Hi. I don't know if i'm doing something wrong, but i have the following issue: I have the route router.add({ name: 'index', pattern: '/(|index)', page: '/home' }) and this works for both url / and /index, which is what i want. But, when i have a Link that goes to the route index, the url changes to /(%7Cindex), and i wanted to go to / . My question is: there is a way to choose what pattern i would like to show on the url when i click on a Link?

I found a way to make it work by using two differents routes: router.add({ name: 'home', pattern: '/', page: '/home' }) and router.add({ name: 'index', pattern: '/index', page: '/home' }), but i wanted to know if there was a way to make the same without duplicating the route.

gvergnaud commented 5 years ago

Hi! Currently, you can't define patterns using a regex-like syntax, like (x|y). The only feature of the pattern string is to have parameters (e.g. /users/:name). I will probably add support for this kind of patterns in the next version though, se #16 for more details.