returned null values in getStaticPaths

Viewed 46

I am trying to return in my params the values of the slug and tags , please notice that tags is not an array it's just a string.

export async function getStaticPaths() {
  const chapters = await client.fetch(
    `*[_type == "chapters" && defined(slug.current)] {
      "slug": slug.current,
      "tags": tags
    }`
  );
  return {
    paths: chapters.map((s : any) => ({params: {slug : s.slug,tags: s.tags}})),
    fallback: false,
  }
}

So when I try to get the tags value in my getStaticProps I get a null value, yet slug is not null.

export async function getStaticProps(context: any) {
  const { slug = "",tags="" } = context.params
  const suggestions = await client.fetch(`
  *[_type == "chapters" && tags == $tags][0]
`, { tags })

when I try to replace the tags value in getStaticProps with a defined value , it fetches the document successfully ,this means the tags value received from getStaticPaths is null. How can I solve this issue ?

1 Answers

I hope it helps you, as far as I know and excuse me if I'm wrong, Incremental Static Regeneration

getStaticPaths: only one params is placed in this case it could be slug

getStaticProps: the params only receive slug , if you want to place several then use query, but you will lose Incremental Static Regeneration, in a nutshell you will not be able to place getStaticPaths

Related