无法导出带有 getServerSideProps 的页面

Pages with `getServerSideProps` can not be exported

我想我在这里造成了某种混乱。

根据 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

错误提供的link说我无法导出。但我使用了以下文档中的示例:

import React from "react"

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

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

export default Page

我是否必须在某处更改某些配置?

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

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

一种可能是使用 getInitialProps

getStaticProps() 是在以下条件下要走的路:

  • The data required to render the page is available at build time ahead of a user’s request
  • The data comes from a headless CMS
  • The data can be publicly cached (not user-specific)
  • The page must be pre-rendered (for SEO) and be very fast — getStaticProps generates HTML and JSON files, both of which can be cached by a CDN for performance

请参阅此处了解何时使用 getStaticPropsgetServerSideProps