# Astro에 통합하기

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

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

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

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

---

먼저 [설치 및 기본 사용법](https://docs.univer.ai/ko-KR/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 UniverPresetSheetsCorekoKR from '@univerjs/preset-sheets-core/locales/ko-KR'
  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.KO_KR,
      locales: { [LocaleType.KO_KR]: mergeLocales(UniverPresetSheetsCorekoKR) },
      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>
```
