# Интеграция в Astro

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

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

- Requested language: `ru-RU`

- Content language: `ru-RU`

- Documentation version: `1.2.0`

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

---

Сначала прочитайте [установку и базовую настройку](https://docs.univer.ai/ru-RU/guides/sheets/getting-started/installation.md). В этом примере Astro монтирует Univer Sheets в контейнер с явно заданной высотой.

Используйте обычный `<script>` для прямой инициализации редактора в браузере. Инициализируйте при первой загрузке и на `astro:page-load`, освобождайте экземпляр на `astro:before-swap` при использовании ClientRouter. Не импортируйте редактор во frontmatter Astro. См. [события навигации Astro](https://docs.astro.build/en/reference/modules/astro-transitions/).

### Шаги интеграции

1. Инициализируйте Univer в `mount()` / `astro:page-load`.
2. Освободите Univer в `astro:before-swap`.

### Пример кода

```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 UniverPresetSheetsCoreruRU from '@univerjs/preset-sheets-core/locales/ru-RU'
  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.RU_RU,
      locales: { [LocaleType.RU_RU]: mergeLocales(UniverPresetSheetsCoreruRU) },
      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>
```
