Skip to content

Astro Folha de referência

Framework web para sites voltados a conteúdo — por padrão, entrega zero JavaScript.

01

Primeiros passos

Componente

Frontmatter entre ---, seguido do template HTML.

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

<h1>{title}</h1>

Props

Props são passadas via Astro.props.

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

<h1>Hello {name}</h1>

Páginas

Roteamento baseado em arquivos em src/pages/.

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

Recursos

Islands

Diretivas client: para hidratação: load, idle, visible, only.

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

<Counter client:load />

Rotas dinâmicas

getStaticPaths para rotas dinâmicas em SSG.

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

Content Collections

Coleções de conteúdo com tipagem segura.

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

Was this helpful?