从 Next.js 10 开始,该getStaticPaths
函数返回一个必须包含非常重要的fallback
密钥的对象,如下所示: https: //nextjs.org/docs/basic-features/data-fetching#the-fallback-key-required
虽然文档很精确,但对于刚开始使用 Next.js 的人来说很难理解,有人可以尝试提供这些选项的更简单或更具体的概述吗?
我认为这是一个非常普通的问题,但我在谷歌上找不到任何东西。
我正在学习 NextJs(使用 TypeScript)并且我有一个站点成功地使用动态路由、SSR 和增量再生,所有设置和部署到 Vercel。这是我的动态路由处理程序中的GetStaticProps
和GetStaticPaths
代码示例:
export const getStaticPaths: GetStaticPaths = async () => {
const routes = new CmsHelper().GetRoutes();
const paths = (await routes).items.map((item, index, items) => {
return item.fields.urlPath;
})
return {
paths: paths,
fallback: 'blocking',
};
}
export const getStaticProps: GetStaticProps = async (context) => {
const urlParts = context.params?.url as string[] || [];
const urlPath = `/${urlParts.join('/')}`;
const article = await new CmsHelper().GetArticle(urlPath);
return {
props: {
article
},
revalidate: 10,
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试 Next.js 并构建一个小应用程序,该应用程序从安装了 GraphQL 的无头 WordPress 应用程序中获取帖子。然后我使用 Apollo/Client 来获取 GraphQL 内容:
apollo-client.js
import { ApolloClient, InMemoryCache } from "@apollo/client";
const client = new ApolloClient({
uri: process.env.WORDPRESS_GRAPHQL_ENDPOINT,
cache: new InMemoryCache(),
});
export default client;
Run Code Online (Sandbox Code Playgroud)
在索引中,我抓住了帖子:
索引.js
import Head from "next/head";
import styles from "../styles/Home.module.css";
import { gql } from "@apollo/client";
import Link from "next/link";
import client from "../apollo-client";
function Home(props) {
const { posts } = props;
return (
<div className={styles.container}>
<Head>
<title>Wordpress blog posts</title>
<meta
name="description"
content="Wordpress blog posts with …
Run Code Online (Sandbox Code Playgroud) 在 NextJS 生产模式 - 在增量静态再生中,我将自动重新验证间隔设置为 604800 秒(7 天)。与此同时,我可能需要在间隔时间开始之前更新特定页面。
如何在间隔/ISR 时间开始之前重建/更新特定页面而不重建整个站点?