【问题标题】:Next JS Static Site: Redirect specific routes to another site?Next JS 静态站点:将特定路由重定向到另一个站点?
【发布时间】:2022-01-18 23:20:16
【问题描述】:
【问题讨论】:
标签:
next.js
amazon-cloudfront
【解决方案1】:
在getStaticProps 函数中,有一个返回重定向值的选项。这允许重定向到内部和外部资源。
您可以将下面的代码保存在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