0

I have a blog using Nuxt 3 and Nuxt Content. My posts are divided into several categories. For each category, there is a page listing all posts belonging to this category. I do this with a generic category page and a validation function that checks if posts with this category exist.

Depending on the number of posts with the given category, the page layout changes. That means that I need the number of posts inside the validation function, and again outside of it. Is there a better/cleaner way of doing this than calculating it in the validation function from its argument, and calculating it again outside of it?

definePageMeta({
  validate: async (route) => {
    return (await queryContent(route.path).find()).length > 0;
  },
});

const { path } = useRoute();
const number = (await queryContent(path).find()).length;
muell
  • 383
  • 1
  • 15

0 Answers0