aymericzip/intlayer-skills / skills/intlayer-preact
intlayer-preact
VerifiedIntegrates Intlayer internationalization with Preact applications. Use when the user asks to "setup Preact i18n", create a new translated component, use the "useIntlayer" hook in Preact, or configure providers.
| File | Kind | Size |
|---|---|---|
| LICENCE.md | markdown | 10.7 KB |
| SKILL.md | skill md | 2.7 KB |
| references/compiler.md | markdown | 14.6 KB |
| references/concept_collections.md | markdown | 5.6 KB |
| references/concept_variants.md | markdown | 20.9 KB |
| references/environment_astro_preact.md | markdown | 37.9 KB |
| references/environment_vite-and-preact.md | markdown | 53.3 KB |
| references/formatters.md | markdown | 17.3 KB |
| references/packages_intlayer_exports.md | markdown | 12.4 KB |
| references/packages_preact-intlayer_exports.md | markdown | 3.2 KB |
| references/packages_preact-intlayer_usePathname.md | markdown | 3.3 KB |
references/packages_preact-intlayer_usePathname.md
View on GitHub---
createdAt: 2026-06-22
updatedAt: 2026-09-27
priority: 5
title: usePathname Hook Documentation | preact-intlayer
description: "Use usePathname in Preact to read the current pathname without its locale segment, for locale-aware navigation and active links."
keywords:
- usePathname
- pathname
- locale
- Intlayer
- Internationalization
- Documentation
- Preact
- JavaScript
slugs:
- doc
- packages
- preact-intlayer
- usePathname
history:
- version: 10.0.0
date: 2026-06-23
changes: "Add usePathname utility"
- version: 8.2.0
date: 2026-06-22
changes: "Init history"
author: aymericzip
---
# Preact Integration: `usePathname` Hook Documentation
The `usePathname` hook returns the current browser pathname with the locale segment stripped. It is useful for building locale-aware navigation (for example, determining which nav item is active) without having to manually remove the locale prefix.
## Importing `usePathname` in Preact
```typescript
import { usePathname } from "preact-intlayer";
```
## Overview
`usePathname` reads `window.location.pathname`, strips the locale prefix via `getPathWithoutLocale`, and re-renders the component whenever the browser fires a `popstate` event (back/forward navigation). It returns an empty string during server-side rendering.
## Usage
```tsx fileName="src/components/NavItem.tsx"
import type { FunctionComponent } from "preact";
import { usePathname } from "preact-intlayer";
type NavItemProps = {
href: string;
label: string;
};
const NavItem: FunctionComponent<NavItemProps> = ({ href, label }) => {
const pathname = usePathname();
const isActive = pathname === href;
return (
<a href={href} aria-current={isActive ? "page" : undefined}>
{label}
</a>
);
};
export default NavItem;
```
## Return Value
| Type | Description |
| -------- | ------------------------------------------------------------------------------------------ |
| `string` | The current pathname without the locale prefix. Empty string during server-side rendering. |
## Behavior
- **Locale stripping**: Removes the leading locale segment (e.g. `/en/dashboard` → `/dashboard`).
- **Reactive**: Updates automatically on `popstate` events (browser back / forward navigation).
- **SSR-safe**: Returns `""` when `window` is not available.
- **Cleanup**: The `popstate` listener is removed automatically when the component unmounts.
## Example
```tsx fileName="src/components/Sidebar.tsx"
import type { FunctionComponent } from "preact";
import { usePathname } from "preact-intlayer";
const links = [
{ href: "/dashboard", label: "Dashboard" },
{ href: "/settings", label: "Settings" },
];
const Sidebar: FunctionComponent = () => {
const pathname = usePathname();
return (
<nav>
{links.map(({ href, label }) => (
<a
key={href}
href={href}
style={{ fontWeight: pathname === href ? "bold" : "normal" }}
>
{label}
</a>
))}
</nav>
);
};
export default Sidebar;
```
## Related
- [`useLocale`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/preact-intlayer/exports.md)
- [`getPathWithoutLocale`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getPathWithoutLocale.md)
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: 322k | 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: 198k | 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: 198k | 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: 198k | Updated | Claude CodeCodex | Verified | Install |