Skip to content

aymericzip/intlayer-skills / skills/intlayer-vue

intlayer-vue

Verified

Integrates Intlayer internationalization with Vue.js and Nuxt applications. Use when the user asks to "setup Vue i18n", use the "useIntlayer" composable, or manage translations in Vue components.

references/packages_vue-intlayer_useRewriteURL.md

View on GitHub
---
updatedAt: 2025-08-23
priority: 5
createdAt: 2025-08-23
title: "useRewriteURL Composable Documentation | vue-intlayer"
description: Vue-specific composable for managing localized URL rewrites in Intlayer.
keywords:
  - useRewriteURL
  - vue-intlayer
  - vue
  - internationalization
  - i18n
slugs:
  - doc
  - packages
  - vue-intlayer
  - useRewriteURL
author: aymericzip
---

# useRewriteURL Composable

The `useRewriteURL` composable for Vue 3 is designed to handle localized URL rewrites on the client side. It automatically corrects the browser's URL to its "pretty" localized version based on the user's current locale and the configuration in `intlayer.config.ts`.

It works by using `window.history.replaceState`, which avoids triggering unwanted Vue Router navigations.

## Usage

Call the composable within your `setup()` function or `<script setup>`.

```vue
<script setup>
import { useRewriteURL } from "vue-intlayer";

// Automatically correct /fr/tests to /fr/essais in the address bar if a rewrite rule exists
useRewriteURL();
</script>

<template>
  <router-view />
</template>
```

## How it works

1. **Reactive Monitoring**: The composable sets up a `watch` on the user's `locale`.
2. **Rewrite Matching**: Whenever the locale changes (or on mount), it checks if the current `window.location.pathname` matches a canonical route that has a prettier localized alias.
3. **URL Correction**: If a prettier alias is found, the composable calls `window.history.replaceState` to update the address bar without reloading the page or losing router state.

## Why use it?

- **SEO Optimization**: Ensures search engines index the authoritative localized version of your URLs.
- **Improved UX**: Corrects manually entered URLs to reflect your preferred naming (e.g., `/fr/a-propos` instead of `/fr/about`).
- **Low Overhead**: Silently updates the URL without re-triggering component lifecycles or navigation guards.

---
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: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall