Nextjs getstaticpaths in build time tries to render un existing paths

46 Views Asked by At

Now this is my situation:

My file structure:

enter image description here

My UI structure:

enter image description here

So, when i access the routes outside "Folder 1" ( [docsSlug].js ) (Home, Article 1, Article 2, ...) they work fine but when i go inside the folder on "Catch All Routes" ( [...subDocsSlug].js ) they work fine until i refresh the page. When i refresh the page it gives me error that something is undefined. When i try to build the project i see that it tries to generate some paths which are inside "Folder 1" but without the /folder-1/ path segment. for example it tries to generate these paths:

> Export encountered errors on following paths:
    /docs/[...subDocsSlug]: /docs/art-inside-folder-1
    /docs/[...subDocsSlug]: /docs/art-inside-folder-2
    /docs/[...subDocsSlug]: /docs/article-inside-3

while the correct path is /docs/folder-1/art-inside-folder-1. Please note that it also renders the correct paths but it tries to render these wrong ones additionally.

This is my GraphQL query:

export const DOCS = gql`
  query {
    docArticles(sort: "customSort") {
      data {
        attributes {
          Title
          Slug
          AdditionalDocs {
            Title
            Slug
          }
        }
      }
    }
  }
`;

and this is my getStaticPaths code in the [...subDocsSlug].js file:

export const getStaticPaths = async () => {
  const { data } = await client.query({
    query: DOCS,
  });

  const docs = data?.docArticles?.data;

  const paths = docs.map((path) => {
    return path.attributes.AdditionalDocs.map((subPath) => {
      
      return { params: { subDocsSlug: [subPath.Slug] } }
    });
  });

  const mergedPaths = paths.flat(1);

  return {
    paths: mergedPaths || null,
    fallback: false,
  };
};

What am i doing wrong here? Any help would be appreciated!

0

There are 0 best solutions below