<NuxtLink>
Nuxt provides <NuxtLink>
component to handle any kind of links within your application.
<NuxtLink>
is a drop-in replacement for both Vue Router's <RouterLink>
component and HTML's <a>
tag. It intelligently determines whether the link is internal or external and renders it accordingly with available optimizations (prefetching, default attributes, etc.)
In this example, we use <NuxtLink>
component to link to a website.
<template> <NuxtLink to="https://nuxtjs.org"> Nuxt website </NuxtLink> <!-- <a href="https://nuxtjs.org" rel="noopener noreferrer">...</a> --></template>
In this example, we use <NuxtLink>
component to link to another page of the application.
<template> <NuxtLink to="/about"> About page </NuxtLink> <!-- <a href="/about">...</a> (+Vue Router & prefetching) --></template>
target
and rel
AttributesIn this example, we use <NuxtLink>
with target
, rel
, and noRel
props.
<template> <NuxtLink to="https://twitter.com/nuxt_js" target="_blank"> Nuxt Twitter </NuxtLink> <!-- <a href="https://twitter.com/nuxt_js" target="_blank" rel="noopener noreferrer">...</a> --> <NuxtLink to="https://discord.nuxtjs.org" target="_blank" rel="noopener"> Nuxt Discord </NuxtLink> <!-- <a href="https://discord.nuxtjs.org" target="_blank" rel="noopener">...</a> --> <NuxtLink to="https://github.com/nuxt" no-rel> Nuxt GitHub </NuxtLink> <!-- <a href="https://github.com/nuxt">...</a> --> <NuxtLink to="/contact" target="_blank"> Contact page opens in another tab </NuxtLink> <!-- <a href="/contact" target="_blank" rel="noopener noreferrer">...</a> --></template>
to
. If used with to
, href
will be ignoredtarget
attribute value to apply on the linkrel
attribute value to apply on the link. Defaults to "noopener noreferrer"
for external links.true
, no rel
attribute will be added to the linkactive-class
prop on internal links. Defaults to Vue Router's default ("router-link-active"
)exact-active-class
prop on internal links. Defaults to Vue Router's default "router-link-exact-active"
)replace
prop on internal linksaria-current
attribute value to apply on exact active links. Works the same as Vue Router's aria-current-value
prop on internal linkstrue
) or internal (false
). This is helpful to handle edge-cases<NuxtLink>
should wrap its content in an <a>
element. It allows taking full control of how a link is rendered and how navigation works when it is clicked. Works the same as Vue Router's custom
propYou can overwrite <NuxtLink>
defaults by creating your own link component using defineNuxtLink
.
export default defineNuxtLink({ componentName: 'MyNuxtLink', /* see signature below for more */})
You can then use <MyNuxtLink />
component as usual with your new defaults.
defineNuxtLink
SignaturedefineNuxtLink({ componentName?: string; externalRelAttribute?: string; activeClass?: string; exactActiveClass?: string; prefetchedClass?: string;}) => Component
<NuxtLink>
component.rel
attribute value applied on external links. Defaults to "noopener noreferrer"
. Set it to ""
to disablelinkActiveClass
option. Defaults to Vue Router's default ("router-link-active"
)linkExactActiveClass
option. Defaults to Vue Router's default ("router-link-exact-active"
)