question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rewrites not working on client-side navigation in 12.2+

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Binaries:
  Node: 14.20.0
  npm: 6.14.17
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.1-canary.0
  react: 18.2.0
  react-dom: 18.2.0

Describe the Bug

When using version 12.2 or higher, rewrites don’t work on client-side navigation anymore. It does work when visiting a url directly / refreshing the page. Initially reported in https://github.com/vercel/next.js/issues/38338.

Expected Behavior

Client-side navigations work the same as server-side page loads.

Link to reproduction

https://github.com/luukdv/next-bug

To Reproduce

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

3reactions
chriliscommented, Oct 8, 2022

@luukdv Having the same issue (maybe related to #39638 and #39837) I found that replacing the trailing slash of the source with {/}? does fix the rewrites on client-side navigation.

{
-  source: "/pages/test/",
+  source: "/pages/test{/}?",
   destination: "https://example.com/",
}

I do not know if this is a bug or the documentation should be updated:

If you’re using trailingSlash: true, you also need to insert a trailing slash in the source parameter. If the destination server is also expecting a trailing slash it should be included in the destination parameter as well.

2reactions
chriliscommented, Oct 14, 2022

For the home page we used /{/}?, which worked for us @luukdv. But not sure if that is actually a good idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rewrites not working in dev server client side navigation in ...
This worked perfectly in Next.js through 12.1 but now when I am testing out 12.2, client-side (SPA) navigation in the dev server is...
Read more >
Rewrites - next.config.js
Rewrites allow you to map an incoming request path to a different destination path. Rewrites act as a URL proxy and mask the...
Read more >
Next.js 12.2 Overview: Middleware, Layouts, and more
Next.js 12.2 introduces stable Middleware and On-Demand ISR, experimental Edge SSR and API Routes, and more.0:00 Intro1:50 Agenda2:30 ...
Read more >
Using Sessions and Session Persistence - Oracle Help Center
The extended session ID format will be part of the URL if URL rewriting is ... If you do not allocate sufficient heap...
Read more >
JavaScript Tutorial: The Basics
JavaScript is the most widely used client-side programming language ... Run the script by loading the HTML file into a JavaScript-capable ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found