---
title: "useLocaleSeo"
description: "为多语言站点注入 hreflang alternate 链接、x-default 与 og:locale，让搜索引擎正确识别各语言版本。layer 的 app.vue 已全局调用；只有在项目中重写 app.vue 时需要自行调用。"
canonical_url: "https://docs.mhaibaraai.cn/docs/reference/composables/use-locale-seo"
---
# useLocaleSeo

> 为多语言站点注入 hreflang alternate 链接、x-default 与 og:locale，让搜索引擎正确识别各语言版本。layer 的 app.vue 已全局调用；只有在项目中重写 app.vue 时需要自行调用。

`useLocaleSeo()` 只在启用 `@nuxtjs/i18n` 且有效语言不少于 2 个时生效，否则直接返回，不注入任何标签。

## 用法

```vue [app/app.vue]
<script setup lang="ts">
await useDocsShell()
useLocaleSeo()
</script>
```

## 签名

```ts
function useLocaleSeo(): void
```

## 注入内容

| 标签 | 值 |
| --- | --- |
| `<link rel="alternate" hreflang="{code}">` | 每个有效语言一条，`href` 为 `site.url` 加该语言下的当前页路径 |
| `<link rel="alternate" hreflang="x-default">` | 指向语言列表中第一个语言的当前页 |
| `<meta property="og:locale">` | 当前语言代码，`-` 替换为 `_`，如 `zh_CN` |

## 注意事项

- 链接是绝对地址，需要在 `nuxt.config` 中配置 `site.url`。
- 目标语言下不存在的页面（`switchLocalePath` 返回空）不会生成对应的 alternate。

## 相关

- [国际化](https://docs.mhaibaraai.cn/docs/guide/i18n)
- [useMovkI18n](https://docs.mhaibaraai.cn/docs/reference/composables/use-movk-i18n)

## 更新日志

See commit history for [layer/app/composables/useLocaleSeo.ts](https://github.com/mhaibaraai/movk-nuxt-docs/commits/main/layer/app/composables/useLocaleSeo.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-nuxt-docs/blob/main/layer/app/composables/useLocaleSeo.ts)


## Sitemap

See the full [sitemap](https://docs.mhaibaraai.cn/sitemap.md) for all pages.
