Nuxt & Universal SSR (50 Qs)•Part 1: Nuxt 3 Fundamentals (Junior / Entry-Level)
What is the `<NuxtLink>` component and how does it optimize navigation?
junior LevelCode ExampleComponentsRoutingVue & Nuxt
In Simple Words:
<NuxtLink> replaces traditional <a> tags for internal and external links. It provides seamless client-side single-page transitions and automated background prefetching.
Optimization Features:
- Smart Prefetching: When a
<NuxtLink>enters the user's viewport, Nuxt automatically prefetches the payload and JavaScript chunks for that target route in the background usingrequestIdleCallback. - Intelligent Protocol Detection: If the
hrefstarts withhttps://ormailto:, it automatically renders as a standard external link (rel="noopener noreferrer"). - Active Class Matching: Automatically applies
router-link-activeandrouter-link-exact-activeCSS classes.
vue
<template>
<!-- Automatically prefetched when scrolled into view -->
<NuxtLink to="/dashboard" prefetch class="nav-btn">
Dashboard
</NuxtLink>
<!-- External link automatically handled -->
<NuxtLink to="https://github.com" target="_blank">
GitHub
</NuxtLink>
</template>