相关疑难解决方法(0)

在 Next.js SSR/ISR 中,回退 false 与 true 与阻塞 getStaticPaths(带或不带重新验证)之间有什么区别?

从 Next.js 10 开始,该getStaticPaths函数返回一个必须包含非常重要的fallback密钥的对象,如下所示: https: //nextjs.org/docs/basic-features/data-fetching#the-fallback-key-required

虽然文档很精确,但对于刚开始使用 Next.js 的人来说很难理解,有人可以尝试提供这些选项的更简单或更具体的概述吗?

next.js

44
推荐指数
2
解决办法
3万
查看次数

如何清除 NextJs GetStaticPaths 缓存/“取消发布”动态路由?

我认为这是一个非常普通的问题,但我在谷歌上找不到任何东西。

我正在学习 NextJs(使用 TypeScript)并且我有一个站点成功地使用动态路由、SSR 和增量再生,所有设置和部署到 Vercel。这是我的动态路由处理程序中的GetStaticPropsGetStaticPaths代码示例:

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)

typescript contentful next.js

7
推荐指数
1
解决办法
5822
查看次数

Next.js ISR页面在CMS中删除后没有被删除

我正在尝试 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)

reactjs next.js getstaticprops getstaticpaths

5
推荐指数
1
解决办法
299
查看次数

Next.js ISR(增量静态再生),如何在间隔/ISR时间开始之前手动或动态重建或更新特定页面?

在 NextJS 生产模式 - 在增量静态再生中,我将自动重新验证间隔设置为 604800 秒(7 天)。与此同时,我可能需要在间隔时间开始之前更新特定页面。

如何在间隔/ISR 时间开始之前重建/更新特定页面而不重建整个站点?

javascript node.js next.js

5
推荐指数
1
解决办法
3609
查看次数