首页 > 解决方案 > NextJs 重写产生 localhost redirected you too many times 错误

问题描述

以下是我的 next.config.js:

// next.config.js

module.exports = {
  async rewrites() {
    return [
      {
        source: '/results',
        destination: 'https://mywebsite.com/results',
      },
    ];
  },
};

根据 Nextjs 重写文档(https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewriting-to-an-external-url),访问 https://nextjswebsite.com/results,页面内容应改写为https://mywebsite.com/results的内容。

但是,我最终得到“本地主机重定向你太多次”。

任何想法是什么导致错误?

标签: javascripturl-rewritingnext.jsbackend

解决方案


所以显然我只需要在目的地有一个尾斜线

// next.config.js

module.exports = {
  async rewrites() {
    return [
      {
        source: '/results',
        destination: 'https://mywebsite.com/results/',
      },
    ];
  },
};

推荐阅读