Skip to content

Astro Hoja de referencia

Framework web para sitios orientados a contenido: envía cero JS por defecto.

01

Primeros pasos

Componente

Frontmatter entre ---, luego la plantilla HTML.

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

<h1>{title}</h1>

Props

Props mediante Astro.props.

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

<h1>Hello {name}</h1>

Páginas

Enrutado basado en archivos en src/pages/.

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

Características

Islands

Directivas client: para la hidratación: load, idle, visible, only.

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

<Counter client:load />

Rutas dinámicas

getStaticPaths para rutas dinámicas en SSG.

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

Content Collections

Colecciones de contenido con tipos seguros.

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

Was this helpful?