Search code examples
javascriptreactjsrefreshnext.js

Next.js links refresh the page


I have a Next.js blog with only 2 routes: / and /posts/:slug.

When I'm on /posts/my-post-title, and I click on the back link (to /), all is fine. The page loads fast (no refresh).

When I'm on /, and I click on /posts/my-post-title, the page refreshes and I can't figure out why. Any suggestion?

Links: blog, sources


Solution

  • I just found the answer...

    Because I map dynamically /posts/:slug to /posts?slug=:slug in my config (in order to reach posts.jsx), I need to do the same with the Link component (via the property as).