Skip to content

Astro Spickzettel

Web-Framework für inhaltsorientierte Websites — standardmäßig ohne JavaScript im Auslieferungspaket.

01

Einstieg

Komponente

Frontmatter zwischen ---, danach die HTML-Vorlage.

astro
---
const title = "Hello";
---

<h1>{title}</h1>

Props

Props über Astro.props.

astro
---
interface Props { name: string; }
const { name } = Astro.props;
---

<h1>Hello {name}</h1>

Seiten

Dateibasiertes Routing in src/pages/.

astro
---
// src/pages/index.astro
---
<html><body>Hello</body></html>
02

Funktionen

Islands

client:-Direktiven für Hydration: load, idle, visible, only.

astro
---
import Counter from "../components/Counter.tsx";
---

<Counter client:load />

Dynamische Routen

getStaticPaths für dynamische SSG-Routen.

astro
---
export async function getStaticPaths() {
  return posts.map(p => ({ params: { slug: p.slug }, props: p }));
}
const post = Astro.props;
---

Content Collections

Typsichere Content Collections.

astro
---
import { getCollection } from "astro:content";
const posts = await getCollection("blog");
---

Was this helpful?