Nuxt/docs/3.api/3.utils/preload-route-components.md
Sébastien Chopin f26a801775
docs: update to new website (#23743)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
2023-10-18 12:59:43 +02:00

1.2 KiB

title description links
preloadRouteComponents preloadRouteComponents allows you to manually preload individual pages in your Nuxt app.
label icon to size
Source i-simple-icons-github https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/preload.ts xs

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.

::callout{color="green" icon="i-ph-rocket-launch-duotone"} Nuxt already automatically preloads the necessary routes if you're using the NuxtLink component. ::

:read-more{to="/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 function
preloadRouteComponents('/dashboard')

const submit = async () => {
  const results = await $fetch('/api/authentication')

  if (results.token) {
    await navigateTo('/dashboard')
  }
}

:read-more{to="/docs/api/utils/navigate-to"}

::callout On server, preloadRouteComponents will have no effect. ::