preloadComponents
preloadRouteComponent
allows you to manually preload individual pages in your Nuxt app.
Preloading routes loads the components of a given route that the user might navigate to in future. This ensures that the components are available earlier and less likely to block the navigation, improving performance.
Nuxt already automatically preloads the necessary routes if you're using the
NuxtLink
component. Read more in Docs > Api > Components > Nuxt Link.
Example
Preload a route when using navigateTo
.
// we don't await this async function, to avoid blocking rendering// this component's setup functionpreloadRouteComponents('/dashboard')const submit = async () => { const results = await $fetch('/api/authentication') if (results.token) { await navigateTo('/dashboard') }}
Read more in Docs > Api > Composables > Navigate To.
Currently, on server,
preloadRouteComponents
will have no effect.