0

I am wondering if its possible to add additional params inside the getStaticProps function? because I want to query the posts in its category name instead of the category slug so here is what it looks like

export const getStaticPaths: GetStaticPaths = async () => {
  const res = await getAllCategories();

  const paths = res.map((category) => ({
    params: {
      slug: category.slug,
      name: category.name // This is the one I want to add but this is undefined in the getStaticProps
    },
  }));

  return {
    paths,
    fallback: true,
  };
};
  • What's the problem with querying the posts by category slug? It seemingly exists on the category. – Mart Aug 12 '22 at 15:06
  • Well I have one category that's three words long, Tech & Science, and as slugs they looks like tech-and-science – John Kim Querobines Aug 12 '22 at 15:09
  • But on the category object, is it the case that the slug property is formatted like `tech-and-science`? In that case, you would simply be able to query the categories like that. Otherwise, I suggest you add a slug property that is formatted like you would want to see it in the route. – Mart Aug 12 '22 at 15:15
  • So I guess it's not possible to add additional params then? maybe i'll just do additional query – John Kim Querobines Aug 12 '22 at 15:40
  • Assuming your dynamic route is something like `[slug].js`, you can only pass a `slug` parameter to `getStaticProps`. If you want to pass multiple parameters, you have to either use a catch-all dynamic route or multiple nested dynamic routes. – juliomalves Aug 13 '22 at 13:30

0 Answers0