Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Commit 31a88be

Browse files
committed
docs: explain usage of inertia link
fix #179
1 parent ac0a04d commit 31a88be

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/usage/inertia.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,56 @@ bun test
193193
```
194194

195195
:::
196+
197+
## Updating the `Link` Component for Inertia
198+
199+
To integrate Inertia's navigation capabilities, you need to update the `Link` component in Vue UI to utilize the `Link` component from `@inertiajs/vue3`. This ensures seamless handling of internal links within your Inertia application.
200+
201+
### Steps to Update
202+
203+
1. **Import the `Link` Component**
204+
Begin by importing the `Link` component from Inertia:
205+
206+
```ts
207+
import { Link } from '@inertiajs/vue3'
208+
```
209+
210+
2. **Modify the Template**
211+
Update the `Link` component's template to dynamically use Inertia's `Link` component when the `href` prop is provided:
212+
213+
```vue
214+
<template>
215+
<Primitive
216+
v-bind="href ? {
217+
'as': target === '_blank' ? 'a' : Link, // [!code ++]
218+
'href': disabled ? undefined : href,
219+
'aria-disabled': disabled ? 'true' : undefined,
220+
'role': disabled ? 'link' : undefined,
221+
'tabindex': disabled ? -1 : undefined,
222+
} : as === 'button' ? {
223+
as,
224+
type,
225+
disabled,
226+
} : {
227+
as,
228+
}"
229+
:rel="rel"
230+
:target="target"
231+
:class="resolvedClass"
232+
@click="onClickWrapper"
233+
>
234+
<slot />
235+
</Primitive>
236+
</template>
237+
```
238+
239+
### Explanation of Changes
240+
241+
- When the `href` prop is provided:
242+
- The `as` property dynamically determines whether to render as an `<a>` tag (for external links) or the `Link` component (for internal navigation).
243+
- Accessibility attributes like `aria-disabled` and `tabindex` are conditionally applied based on the `disabled` state.
244+
245+
- When the `href` prop is not provided:
246+
- The component defaults to rendering as a `button` or another specified element, ensuring flexibility for non-link interactions.
247+
248+
This enhancement ensures proper navigation behavior and accessibility within your Inertia-powered application.

0 commit comments

Comments
 (0)