
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your code, I can spot the issue! In your getStaticProps query, you have an extra set of empty brackets [] that's causing problems:
*[_type == "contributionsEcrivain" && defined(slug.current)][] {That [] after your filter is treating the result as an array and trying to slice it, which is likely returning an empty result. Remove it!
However, there's a bigger issue with your approach: you're fetching ALL contributions documents, not just the specific one for the current route. In getStaticProps, you need to filter by the specific contributions slug from the route params:
export async function getStaticProps({ params }) {
const { slug, contributions } = params;
const query = groq`
*[_type == "contributionsEcrivain" && slug.current == $contributionsSlug][0] {
_id,
title,
associatedArtist[0]->{
"slug": slug.current,
title,
},
associatedNumero[0]->{
"slug": slug.current,
number
},
body,
"slug": slug.current,
}
`;
const data = await client.fetch(query, {
contributionsSlug: contributions
});
return {
props: {
contribution: data
}
};
}Key changes:
[] after the filter[0] at the end to get a single document instead of an array$contributionsSlug to filter for the specific contribution matching the routecontributions param from the route to the queryYou could also verify the artist matches to be extra safe:
*[_type == "contributionsEcrivain"
&& slug.current == $contributionsSlug
&& $artistSlug in associatedArtist[]->slug.current][0] {
// ... rest of projection
}And pass both slugs: { contributionsSlug: contributions, artistSlug: slug }
Your getStaticPaths logic looks solid - that's correctly building all the possible route combinations. The issue was just in how you were fetching the data for each specific page!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store