# General Translation React SDKs (gt-react, gt-next, gt-react-native): useLocalizeHref
URL: https://generaltranslation.com/zh/docs/react/nextjs/reference/hooks/use-localize-href.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 对不渲染链接的导航所用的 App Router 路径进行本地化。useLocalizeHref 的 API 参考。

`useLocalizeHref` 钩子返回一个函数，该函数按照与 [`<Link>`](/docs/react/nextjs/link) 相同的规则对路径进行本地化。在不渲染 `<Link>` 的导航场景中可以使用它，例如 `router.push()` 或组件的 `href` 属性。

在客户端组件中，可从 `gt-next/link` 导入；在服务器端组件和客户端组件中，均可从 `gt-next` 导入。在 async 服务器端代码中，请改用 [`getLocalizeHref`](/docs/react/nextjs/reference/functions/get-localize-href)。

## 概览 [#overview]

```tsx title="components/CheckoutButton.tsx"
'use client';

import { useRouter } from 'next/navigation';
import { useLocalizeHref } from 'gt-next/link';

export function CheckoutButton() {
  const router = useRouter();
  const localizeHref = useLocalizeHref();

  return (
    <button onClick={() => router.push(localizeHref('/checkout'))}>
      Checkout
    </button>
  );
}
```

## 返回值 [#returns]

**类型** `(href: string, locale?: string | false) => string`

一个函数，用于按当前区域设置本地化 `href`；若指定了 `locale`，则按 `locale` 进行本地化。传入 `false` 时将原样返回 `href`。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
