hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
116 stars 30 forks source link

Link to dynamic route results in ERR_ABORTED 404 (Not Found), then redirects correctly #54

Closed simonhenke closed 1 year ago

simonhenke commented 1 year ago

Since I've updated from 1.8.0-1 to 1.9.1, some links to dynamic routes show a weird behavior. At first they log the following error to the console ... image ... and then they redirect to the page successfully. Refreshing the page works fine, too, so the issue is most likely related to the link component, not any routes setup.

Here's the folder structure:

pages
   products
       [slug].page.tsx

routes.json inside the products folder:

{
  "/": {
    "de": "produkte"
  }
}

The link looks like this: <Link href={`/products/${product.slug}`}>...</Link>

The debug-mode logs the following object when clicking the link:

image

Workaround After some experimenting, I've found a solution which seems to work. If I built the link like this, the 404 doesn't show up any more: <Link href={{ pathname: "/products/[slug]", query: { slug: product.slug }}}>...</Link>

The debugged objects looks a bit different then:

image

Am I missing something, or is my workaround maybe even the intended way of using links to dynamic routes? However, the initially described code worked perfectly fine before the update.

cvolant commented 1 year ago

Strange, there are some tests checking if both syntax work... :thinking: This is a bug, but yes, your workaround is a correct syntax: I even only use this one.

cvolant commented 1 year ago

It should work with 1.9.2.