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.023/06/2026
- "Initialise history"v8.2.022/06/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf 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
Vue Integration: usePathname Documentation
The usePathname function returns the current browser pathname with the locale segment removed, as a Vue ComputedRef<string>. This is useful for building locale-aware navigation—for example, to determine which nav item is active—without having to strip off the locale prefix manually.
Importing usePathname in Vue
Copy the code to the clipboard
import { usePathname } from "vue-intlayer";Overview
usePathname creates a Vue computed ref that reads window.location.pathname, removes the locale prefix via getPathWithoutLocale, and updates its value whenever the browser fires a popstate event (back/forward navigation). The value can be used directly in your Vue templates or setup functions.
Usage
Copy the code to the clipboard
<script setup lang="ts">import { usePathname } from "vue-intlayer";const props = defineProps<{ href: string; label: string;}>();const pathname = usePathname();</script><template> <a :href="href" :aria-current="pathname === href ? 'page' : undefined"> {{ label }} </a></template>Return Value
Open the table in a modal to view all data content clearly
| Type | Description |
|---|---|
ComputedRef<string> | Vue Computed Ref containing the current browser pathname without the locale prefix. |
Behaviour
- Locale stripping: Removes the leading locale segment (e.g.
/en-GB/dashboard→/dashboard). - Reactive: Updates the value on every
popstateevent (browser back / forward navigation). - SSR-safe: Returns
""whenwindowis unavailable. - Cleanup: The
popstatelistener is added globally upon initialisation and typically does not require manual per-component cleanup, thanks to how Vue manages the lifecycle.
Example
Copy the code to the clipboard
<script setup lang="ts">import { usePathname } from "vue-intlayer";const links = [ { href: "/dashboard", label: "Dashboard" }, { href: "/settings", label: "Settings" },];const pathname = usePathname();</script><template> <nav> <a v-for="link in links" :key="link.href" :href="link.href" :style="{ fontWeight: pathname === link.href ? 'bold' : 'normal' }" > {{ link.label }} </a> </nav></template>Related
useLocale— current locale + locale switchergetPathWithoutLocale— the underlying utility used by this hook