gpt4 book ai didi

next.js - 无法导出 `getServerSideProps` 的页面

转载 作者:行者123 更新时间:2023-12-04 10:10:27 26 4
gpt4 key购买 nike

我想我在这里制造了某种困惑。

根据documentation ,如果我想要页面的服务器端渲染(SSR),我导出异步函数:

getServerSideProps

但是,如果我这样做,我将无法构建在本地或现在 Zeit 运行的项目。
如果我尝试构建或部署,我会得到:

Error for page /_error: pages with getServerSideProps can not be exported. See more info here: https://err.sh/next.js/gssp-export



错误提供的链接说我无法导出。但我使用了以下文档中的示例:
import React from "react"

export async function getServerSideProps() {
return { props: { } }
}

function Page({ data }) {
// Render data...
}

export default Page

我必须在某处更改一些配置吗?

如何防止构建此静态页面?

最佳答案

无法在 _error.js 页面上工作,根据设计决定,如发布的 here由 nextjs 维护人员提供。

一种可能性是使用 getInitialProps , 反而。

关于next.js - 无法导出 `getServerSideProps` 的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61354282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com