Link
Usage
The Link component is a wrapper around <NuxtLink> using the custom prop. It provides a few extra props:
inactive-classprop to set a class when the link is inactive,active-classis used when active.exactprop to style withactive-classwhen the link is active and the route is exactly the same as the current route.exact-queryandexact-hashprops to style withactive-classwhen the link is active and the query or hash is exactly the same as the current query or hash.- use
exact-query="partial"to style withactive-classwhen the link is active and the query partially match the current query.
- use
The incentive behind this is to provide the same API as NuxtLink back in Nuxt 2 / Vue 2. You can read more about it in the Vue Router migration from Vue 2 guide.
Tag
The Link components renders an <a> tag when a to prop is provided, otherwise it renders a <button> tag. You can use the as prop to change fallback tag.
<template>
<PLink as="button">Link</PLink>
</template>
to prop.Style
By default, the link has default active and inactive styles, check out the #theme section.
to prop to see the active and inactive states.You can override this behavior by using the raw prop and provide your own styles using class, active-class and inactive-class.
<template>
<PLink raw to="/docs/pohon/components/link" active-class="font-bold" inactive-class="text-muted">Link</PLink>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'button' | anyThe element or component this component should render as when not a link. |
type | 'button' | "button" | "reset" | "submit"The type of the button when not a link. |
ariaCurrentValue | 'page' | "step" | "time" | "date" | "true" | "false" | "page" | "location"Value passed to the attribute |
autofocus | false | true | "true" | "false" | |
form | string | |
formaction | string | |
formenctype | string | |
formmethod | string | |
formnovalidate | false | true | "true" | "false" | |
formtarget | string | |
name | string | |
referrerpolicy | "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | |
href | string | kt | TtAn alias for
| |
target | string & {} | "_blank" | "_parent" | "_self" | "_top"Where to display the linked URL, as the name for a browsing context.
| |
rel | string & {} | "noopener" | "noreferrer" | "nofollow" | "sponsored" | "ugc"A rel attribute value to apply on the link. Defaults to "noopener noreferrer" for external links.
| |
to | string | kt | TtRoute Location the link should navigate to when clicked on.
| |
activeClass | stringClass to apply when the link is active | |
exactActiveClass | stringClass to apply when the link is exact active | |
download | any | |
hreflang | string | |
media | string | |
ping | string | |
exactQuery | boolean | "partial"Allows controlling how the current route query sets the link as active. | |
inactiveClass | stringThe class to apply when the link is inactive. | |
prefetchedClass | stringA class to apply to links that have been prefetched. | |
prefetchOn | "visibility" | "interaction" | Partial<{ visibility: boolean; interaction: boolean; }>Allows controlling when to prefetch links. By default, prefetch is triggered only on visibility. | |
trailingSlash | "append" | "remove"An option to either add or remove trailing slashes in the | |
active | undefined | booleanForce the link to be active independent of the current route. |
disabled | boolean | |
replace | booleanCalls | |
viewTransition | booleanPass the returned promise of | |
exact | booleanWill only be active if the current route is an exact match. | |
exactHash | booleanWill only be active if the current route hash is an exact match. | |
raw | booleanWhen | |
external | booleanForces the link to be considered as external (true) or internal (false). This is helpful to handle edge-cases | |
noRel | booleanIf set to true, no rel attribute will be added to the link | |
prefetch | booleanWhen enabled will prefetch middleware, layouts and payloads of links in the viewport. | |
noPrefetch | booleanEscape hatch to disable |
Slots
| Slot | Type |
|---|---|
default | { active: boolean; } |
Theme
Below is the theme configuration skeleton for the PLink. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.
export default defineAppConfig({
pohon: {
link: {
base: '',
variants: {
active: {
true: '',
false: ''
},
disabled: {
true: ''
}
},
compoundVariants: []
}
}
};
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'
export default defineAppConfig({
pohon: {
link: {
base: '',
variants: {
active: {
true: '',
false: ''
},
disabled: {
true: ''
}
},
compoundVariants: []
}
}
};