【发布时间】:2021-07-22 16:26:39
【问题描述】:
我试图理解为什么 Next.js 将我的一些页面构建为 SSG,而其中一些页面构建为静态,而它们都使用 getStaticProps。
让我们以我的 404 页面为例,该页面使用 getStaticProps 通过 graphql 从 prismic 中获取数据。它被呈现为静态网站,而我认为它应该呈现为 SSG(因为它使用 getStaticProps)。
我在我的 500 页中做同样的事情,但使用不同的 graphql 查询,并且它被呈现(在我看来是正确的)为 SSG。
这是为什么呢?
404 页面:
const NotFound = ({ data: { page } }) => {
return (
<div className={'not-found'}>
<p className={'not-found__description'}>{RichText.asText(page.description)}</p>
</div>
);
};
export const getStaticProps = async (context) => {
const currentLanguage = getCurrentLocale(context);
const response = await apolloClient.query({
query: gql`
query {
}
`
};
return {
props: {
data: {
page: response
}
}
}
});
export default NotFound;
500 页:
const InternalServerError = ({ data: { page } }) => {
return (
<div className={'internal-server-error'}>
<p className={'internal-server-error__description'}>{RichText.asText(page.description)}</p>
</div>
);
};
export const getStaticProps = async (context) => {
const currentLanguage = getCurrentLocale(context);
const response = await apolloClient.query({
query: gql`
query {
}
`
});
return {
props: {
data: {
page: response
}
}
}
};
【问题讨论】:
标签: javascript build next.js prismic.io