docs icon indicating copy to clipboard operation
docs copied to clipboard

⚠️ Issue Sample code for 'Building for static output (default)' throws a "Property 'render' does not exist on type 'never'"

Open angyan opened this issue 1 year ago • 1 comments

Proposed fix:

---
import { CollectionEntry, getCollection } from "astro:content";

// 1. Generate a new path for every collection entry
export async function getStaticPaths() {
    const blogEntries = await getCollection("blog");
    return blogEntries.map((entry) => ({
        params: { slug: entry.slug },
        props: { entry },
    }));
}

// 2. For your template, you can get the entry directly from the prop
const { entry } = Astro.props as { entry: CollectionEntry<"blog"> };
const { Content } = await entry.render();
---

<h1>{entry.data.title}</h1>
<Content />

angyan avatar Feb 25 '24 19:02 angyan

I couldn't reproduce this somehow. Would it be possible for you to provide a minimal reproduction example?

mingjunlu avatar Feb 28 '24 06:02 mingjunlu

closing for inactivity and not reproducible

sarah11918 avatar Jun 19 '24 16:06 sarah11918