Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Add usePathname utility"v10.0.06/23/2026
- "Init history"v8.2.06/22/2026
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Angular Integration: usePathname Hook Documentation
The usePathname hook returns the current browser pathname with the locale segment stripped, as an Angular Signal<string>. 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 Angular
Copy the code to the clipboard
import { usePathname } from "angular-intlayer";Overview
usePathname reads window.location.pathname, strips the locale prefix via getPathWithoutLocale, and updates the signal whenever the browser fires a popstate event (back/forward navigation). It uses Angular's DestroyRef to clean up the event listener automatically when the component is destroyed.
Usage
Copy the code to the clipboard
import { Component, input } from "@angular/core";import { usePathname } from "angular-intlayer";@Component({ standalone: true, selector: "app-nav-item", template: ` <a [href]="href()" [attr.aria-current]="pathname() === href() ? 'page' : null" > {{ label() }} </a> `,})export class NavItemComponent { readonly href = input.required<string>(); readonly label = input.required<string>(); readonly pathname = usePathname();}Return Value
Open the table in a modal to view all data content clearly
| Type | Description |
|---|---|
Signal<string> | Angular signal containing the current pathname without the locale prefix. |
Behavior
- Locale stripping: Removes the leading locale segment (e.g.
/fr/dashboard→/dashboard). - Reactive: Updates automatically on
popstateevents (browser back / forward navigation). - SSR-safe: Returns
""whenwindowis not available. - Cleanup: The
popstatelistener is removed viaDestroyRef.onDestroywhen the host component is destroyed.
Example
Copy the code to the clipboard
import { Component } from "@angular/core";import { usePathname } from "angular-intlayer";@Component({ standalone: true, selector: "app-sidebar", template: ` <nav> @for (link of links; track link.href) { <a [href]="link.href" [style.font-weight]="pathname() === link.href ? 'bold' : 'normal'" > {{ link.label }} </a> } </nav> `,})export class SidebarComponent { readonly links = [ { href: "/dashboard", label: "Dashboard" }, { href: "/settings", label: "Settings" }, ]; readonly pathname = usePathname();}Related
useLocale— current locale + locale switchergetPathWithoutLocale— the underlying utility used by this hook