01
はじめに
コンポーネント
--- の間にフロントマターを書き、その後に HTML テンプレートを記述します。
astro
---
const title = "Hello";
---
<h1>{title}</h1>Props
Astro.props で props を受け取れます。
astro
---
interface Props { name: string; }
const { name } = Astro.props;
---
<h1>Hello {name}</h1>ページ
src/pages/ のファイルベースルーティングです。
astro
---
// src/pages/index.astro
---
<html><body>Hello</body></html>02
機能
アイランド
クライアント指令でハイドレーションを制御:load、idle、visible、only。
astro
---
import Counter from "../components/Counter.tsx";
---
<Counter client:load />動的ルート
getStaticPaths で動的な SSG ルートを生成します。
astro
---
export async function getStaticPaths() {
return posts.map(p => ({ params: { slug: p.slug }, props: p }));
}
const post = Astro.props;
---コンテンツコレクション
型安全なコンテンツコレクションを利用できます。
astro
---
import { getCollection } from "astro:content";
const posts = await getCollection("blog");
---Was this helpful?