最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Rederict path, specified in 'next.config.js' file for one project, has been implemented for all pro

matteradmin5PV0评论

A bit of an odd one...

I've specified a redirect path for the root index page for one of my projects. It worked no problem and redirected me to the correct path, but now it redirects me to that same path for the root index page for all of my other projects. (trying to visit localhost:3000 now redirects me to localhost:3000/ggp for all of my projects)

I've tried restarting servers, deleting the next.config.js file in the original project, menting out the redirect key, overriding it with a different path in both the original project and in the other project but all to no avail.

This is the first time I've created a next.config.js file and obviously the first time using the redirect key. I was following the guidance in the docs (.config.js/redirects).

At first I thought it might be because I set permanent to true, but that would seem like a bit of a weird feature to make it global and when I run a different project in dev mode (next dev) and debug, everything works normally as it should. So I'm not sure if the value just got cached on first use or something.

Has anybody encountered this before / know a way of fixing it? I'd appreciate your help!

The original next.js.

module.exports = {
  async redirects() {
    return [
      {
        source: '/',
        destination: '/ggp',
        permanent: true,
      },
    ]
  },
}

A bit of an odd one...

I've specified a redirect path for the root index page for one of my projects. It worked no problem and redirected me to the correct path, but now it redirects me to that same path for the root index page for all of my other projects. (trying to visit localhost:3000 now redirects me to localhost:3000/ggp for all of my projects)

I've tried restarting servers, deleting the next.config.js file in the original project, menting out the redirect key, overriding it with a different path in both the original project and in the other project but all to no avail.

This is the first time I've created a next.config.js file and obviously the first time using the redirect key. I was following the guidance in the docs (https://nextjs/docs/api-reference/next.config.js/redirects).

At first I thought it might be because I set permanent to true, but that would seem like a bit of a weird feature to make it global and when I run a different project in dev mode (next dev) and debug, everything works normally as it should. So I'm not sure if the value just got cached on first use or something.

Has anybody encountered this before / know a way of fixing it? I'd appreciate your help!

The original next.js.

module.exports = {
  async redirects() {
    return [
      {
        source: '/',
        destination: '/ggp',
        permanent: true,
      },
    ]
  },
}
Share Improve this question asked Jun 15, 2021 at 16:30 Tom HaytonTom Hayton 1137 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Turns out the problem was that when you set the permanent key to true, it caches the redirect route in the browser (at least it does in Google Chrome), so that redirect route is used for all requests to that path, regardless of which project is active.

Clearing the browser cache and switching the permanent key to false, solves the issue for me (I just opened up the inspector, went to the network tab, right clicked in the network request table and selected "clear browser cache").

It seems like a weird feature to me, especially since it's use seems pretty ambiguous in the docs (although it may be mentioned somewhere that I haven't looked).

Anyway, lesson learned: Test the issue in another browser before tearing your hair out :')

  1. Press Clear site data button on center-bottom on screenshot;
  2. Press Empty cache and hard reload (when DevTools is opened);


My env: Next.js v13.5.3, MacOS, M1, Chrome v117.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far