Next JS 静态站点:将特定路由重定向到另一个站点?

Next JS Static Site: Redirect specific routes to another site?

我使用部署在云端的 Next JS 创建了一个静态站点。我希望通过更改基本路径(例如,如果路由是 www.mysite.com/stuff, it will redirect to www.redirectedSite.com/stuff)将一些路由重定向到另一个站点。这可能吗?如果可以,我将使用什么来设置它?

getStaticProps 函数中,有一个 return 重定向值的选项。这允许重定向到内部和外部资源。

您可以将下面的代码保存在 pages/stuff.tsx 下。当向 /stuff 发出请求时,它们将被重定向。

import { GetStaticProps } from 'next';

export const getStaticProps: GetStaticProps = async () => {
  return {
    redirect: {
      destination: 'http://www.redirectedsite.com/stuff',
      permanent: false,
    },
  };
};

const TestPage = (): JSX.Element => {
  return <div></div>;
};

export default TestPage;

Next JS Documentation on getStaticProps redirect