wpengine / faustjs

Faust.js™ - The Headless WordPress Framework
https://faustjs.org
Other
1.43k stars 132 forks source link

SSG getStaticPaths error #625

Closed lilgujj closed 3 years ago

lilgujj commented 3 years ago

Hello! When trying to use your example code to render static pages i get this error: Error: The provided path / does not match the page: /[...pageUri].

code:

export async function getStaticPaths() {
  const values = await client.client.inlineResolved(() => client.client.query
    .pages()
    ?.nodes?.map((node) => node?.uri));
  const paths = [];

  if (Array.isArray(values)) {
    paths.push(
      ...values
        .filter((value) => typeof value === 'string'),
    );
  }
  return {
    paths,
    fallback: 'blocking',
  };
}

i use contentNodes to fetch the data that looks like this:

const { pageUri } = useRouter().query;

const contentNode = client.useQuery().contentNode({
  id: (pageUri as string[]).join("/"),
  idType: ContentNodeIdTypeEnum.URI,
});

const page = contentNode?.$on?.Page;

getStaticProps looks like this:

export async function getStaticProps(context: GetStaticPropsContext) {
  return getNextStaticProps(context, {
    Page: Slug,
    client,
    notFound: await is404(context, { client }),
  });
}

related issue: #616

lilgujj commented 3 years ago

solved this by changing:

from:

.filter((value) => typeof value === 'string'),

to:

.filter((value) => value !== '/'),

guess its because of [...pageUri] should not render the '/' route? becausei have an seperate index.tsx thats only for the homepage? sorry for inconvenience :)

blakewilson commented 3 years ago

Hey @lilgujj, I'm glad you solved this. I'll close this issue, but if you experience further issues please feel free to open a new issue.