current page not displayed
I can't get current slug from array
stack: backend: Sanity Frontend: Astro.build
Sanity
import { defineField, defineType } from 'sanity'
export default defineType({
name: 'art',
title: 'Arts',
type: 'document',
fields: [
defineField({
name: 'year',
title: 'Year',
type: 'string',
options: {
hotspot: true,
},
}),
defineField({
name: 'images',
title: 'Arts',
type: 'array',
of: [{
name: 'object',
title: 'object',
type: 'object',
options: {
hotspot: true,
},
fields: [{
name: 'image',
type: 'image',
title: 'image',
},
{
name: 'title',
type: 'string',
title: 'Title',
},
{
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
},
},
],
}, ],
}),
]
})
Astro [slug].astro
---
import Layout from '../../layouts/Page.astro'
import { useSanityClient } from "astro-sanity";
export async function getAllArts() {
const query = `*[_type == 'art']`;
const data = await useSanityClient().fetch(query);
return data;
}
export interface Props {
art: any;
}
export async function getStaticPaths() {
const allArtInfo = await getAllArts();
return allArtInfo.map(art => ({params: { slug: art.images.slug.current }, props: {art}}));
}
const { art } = Astro.props;
const seo = {
title: '',
description: '',
}
---
<Layout seo={seo}>
<!-- <h1>{art.title}</h1> -->
</Layout>
Trying to display the current page from the "images" array
As soon as I didn 't write output: Cannot read properties of undefined (reading 'current')
if add [0] before "images"
return allArtInfo.map(art => ({params: { slug: art.images[0].slug.current }, props: {art}}));
the page is displayed with the current slug. only the first array. how to make everything work fine?