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
Solid Integration: usePathname Hook Documentation
The usePathname hook returns the current browser pathname with the locale segment stripped, as a Solid Accessor<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 Solid
Copy the code to the clipboard
import { usePathname } from "solid-intlayer";Overview
usePathname creates a reactive signal initialized from window.location.pathname, strips the locale prefix via getPathWithoutLocale, and updates the signal whenever the browser fires a popstate event (back/forward navigation). The event listener is cleaned up automatically via onCleanup.
Usage
Copy the code to the clipboard
import type { Component } from "solid-js";import { usePathname } from "solid-intlayer";type NavItemProps = { href: string; label: string;};const NavItem: Component<NavItemProps> = ({ href, label }) => { const pathname = usePathname(); return ( <a href={href} aria-current={pathname() === href ? "page" : undefined}> {label} </a> );};export default NavItem;Return Value
Open the table in a modal to view all data content clearly
| Type | Description |
|---|---|
Accessor<string> | Solid accessor (reactive getter) returning 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 automatically via Solid'sonCleanup.
Example
Copy the code to the clipboard
import type { Component } from "solid-js";import { For } from "solid-js";import { usePathname } from "solid-intlayer";const links = [ { href: "/dashboard", label: "Dashboard" }, { href: "/settings", label: "Settings" },];const Sidebar: Component = () => { const pathname = usePathname(); return ( <nav> <For each={links}> {({ href, label }) => ( <a href={href} style={{ "font-weight": pathname() === href ? "bold" : "normal" }} > {label} </a> )} </For> </nav> );};export default Sidebar;Related
useLocale— current locale + locale switchergetPathWithoutLocale— the underlying utility used by this hook