aymericzip/intlayer-skills / skills/intlayer-react
intlayer-react
VerifiedIntegrates Intlayer internationalization with React component. Use when the user asks to "setup React i18n", create a new translated component, use the "useIntlayer" hook, or configure providers.
references/packages_react-intlayer_useRewriteURL.md
View on GitHub---
updatedAt: 2026-09-27
priority: 5
createdAt: 2025-08-23
title: "useRewriteURL Hook Documentation | react-intlayer"
description: "Use useRewriteURL in React to rewrite the browser URL to its localized version, following the custom URL rewrites of your configuration."
keywords:
- useRewriteURL
- react-intlayer
- react
- internationalization
- i18n
slugs:
- doc
- packages
- react-intlayer
- useRewriteURL
author: aymericzip
---
# useRewriteURL Hook
The `useRewriteURL` hook is designed to manage localized URL rewrites on the client side. It automatically detects if the current URL should be corrected to a "pretty" localized version based on the user's locale and the rewrite rules defined in `intlayer.config.ts`.
Unlike standard navigation, this hook uses `window.history.replaceState` to update the URL in the address bar without triggering a full page reload or a router navigation cycle.
## Usage
Simply call the hook in a client-side component.
```tsx
import { useRewriteURL } from "react-intlayer";
const MyComponent = () => {
// Automatically correct /fr/tests to /fr/essais in the address bar if a rewrite rule exists
useRewriteURL();
return <div>My Component</div>;
};
```
## How it works
1. **Detection**: The hook monitors the current `window.location.pathname` and the user's `locale`.
2. **Matching**: It uses the internal Intlayer engine to check if the current pathname matches a canonical route that has a prettier localized alias for the current locale.
3. **URL Correction**: If a better alias is found (and it's different from the current path), the hook calls `window.history.replaceState` to update the browser URL while preserving the same canonical content and state.
## Why use it?
- **SEO**: Ensures that users always land on the single, authoritative pretty URL for a given language.
- **Consistency**: Prevents inconsistencies where a user might manually type a canonical path (like `/fr/privacy-notice`) instead of the localized version (`/fr/politique-de-confidentialite`).
- **Performance**: Updates the address bar without triggering unwanted router side-effects or component re-mounts.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |