相关疑难解决方法(0)

错误:在 /posts/[slug] 的 getStaticPaths 中未以字符串形式提供必需的参数 (slug)

我的项目中有以下 [slug].js 文件:

import Head from "next/head";
import PostContent from "../../components/posts/post-detail/post-content";
import { getPostByName, getAllPosts } from "../../helpers/api-util";

function PostDetailPage(props) {
  const post = props.selectedPost;
  console.log(post);
  if (!post) {
    return (
      <div className="">
        <p>Loading...</p>
      </div>
    );
  }
  return <PostContent post={post.slug} />;
}


export async function getStaticProps(context) {
  const blogSlug = context.params.slug;
  const post = await getPostByName(blogSlug);
  return {
    props: {
      selectedPost: post,
    }, // will be passed to the page component as props
  };
}

export async function getStaticPaths() { …
Run Code Online (Sandbox Code Playgroud)

next.js

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

next.js ×1