Next.js Dynamic Routing - How to Get StaticProps and GetStaticPaths in [slug].js?
The solution is to query both content types together using GROQ's in operator. Since your "numero" and "archive" schemas have the same fields, you can treat them as a single content stream.
Update your getStaticPaths:
export async function getStaticPaths() {
const paths = await client.fetch(
groq`*[_type in ["numero", "archive"] && defined(slug.current)][].slug.current`
);
return {
paths: paths.map((slug) => ({ params: { slug } })),
fallback: true,
};
}Update your getStaticProps:
export async function getStaticProps({ params }) {
const footerLogos = await client.fetch(footerLogoQuery);
// Query both types at once - whichever matches the slug will be returned
const numero = await client.fetch(
groq`*[_type in ["numero", "archive"] && slug.current == $slug][0]`,
{ slug: params.slug }
);
// Handle case where no document is found
if (!numero) {
return {
notFound: true,
};
}
const readMoreData = await client.fetch(numeroReadMoreQuery, {
slug: params.slug,
});
return {
props: {
numero,
readMoreData,
footerLogos,
},
};
}The key is _type in ["numero", "archive"] in your GROQ query. This filters for documents that match either type, so you get a single result regardless of which schema the slug belongs to.
Since both schemas have identical fields, the returned document works the same way in your component. If you ever need to know which type was returned (for conditional logic or analytics), you can check numero._type in your component.
Make sure your numeroReadMoreQuery also handles both types if it filters by _type - just apply the same _type in ["numero", "archive"] pattern there.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.