我发现文档有点模棱两可。给定一个特许经营列表,我想在构建时呈现相关的特许经营详细信息页面,以避免在运行时访问 CMS/API,因为这些页面不会经常更改。
然而,似乎即使相关页面是在构建时使用 生成的getStaticPaths,它们仍然需要getStaticProps在运行时执行调用。这违背了生成静态页面的目的。
import {withLayout} from '../../components/layout';
import {getFranchises} from '../api/franchises';
const Franchise = (props) => {
console.info(props);
return (
<>
<h1>{props.name}</h1>
</>
);
};
export async function getStaticProps({params}) {
let data = await getFranchises();
let franchise = data.find(x => x.id === params.id);
return {
props: franchise
}
}
export async function getStaticPaths() {
let data = await getFranchises();
// Get the paths we want to pre-render based on posts
const paths = …Run Code Online (Sandbox Code Playgroud) next.js ×1