# Astro に統合する

- Human documentation: [https://docs.univer.ai/ja-JP/guides/sheets/getting-started/integrations/astro](https://docs.univer.ai/ja-JP/guides/sheets/getting-started/integrations/astro)

- Agent Markdown: [https://docs.univer.ai/ja-JP/guides/sheets/getting-started/integrations/astro.md](https://docs.univer.ai/ja-JP/guides/sheets/getting-started/integrations/astro.md)

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.1.0`

- Source: [sheets/getting-started/integrations/astro.ja-JP.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/sheets/getting-started/integrations/astro.ja-JP.mdx)

---

まず[インストールと基本的な使い方](https://docs.univer.ai/ja-JP/guides/sheets/getting-started/installation.md)を参照してください。以下は Astro を使い、高さを明示したコンテナーに Univer Sheets をマウントする例です。

通常の `<script>` でブラウザー上にエディターを直接初期化します。初回読み込み時に初期化し、ClientRouter 使用時は `astro:page-load` で再マウント、`astro:before-swap` で破棄します。Astro frontmatter ではエディターをインポートしないでください。[Astro のナビゲーションイベント](https://docs.astro.build/en/reference/modules/astro-transitions/)を参照してください。

### 統合手順

1. `mount()` / `astro:page-load` で Univer を初期化します。
2. `astro:before-swap` で Univer を破棄します。

### サンプルコード

```astro title="src/pages/index.astro"
<div id="univer-sheets" style="height: 600px"></div>

<script>
  import type { Univer } from '@univerjs/presets'
  import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'
  import UniverPresetSheetsCorejaJP from '@univerjs/preset-sheets-core/locales/ja-JP'
  import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'

  import '@univerjs/preset-sheets-core/lib/index.css'

  let univerInstance: Univer | undefined

  function mount() {
    const container = document.getElementById('univer-sheets')
    if (!container || univerInstance) return

    const { univer, univerAPI } = createUniver({
      locale: LocaleType.JA_JP,
      locales: { [LocaleType.JA_JP]: mergeLocales(UniverPresetSheetsCorejaJP) },
      presets: [UniverSheetsCorePreset({ container })],
    })

    univerAPI.createWorkbook({})
    univerInstance = univer
  }

  function dispose() {
    univerInstance?.dispose()
    univerInstance = undefined
  }

  mount()
  document.addEventListener('astro:page-load', mount)
  document.addEventListener('astro:before-swap', dispose)
</script>
```
