preloadRouteComponents
preloadRouteComponents 允許您手動預載入 Nuxt 應用程式中的單個頁面。
預載入路由會載入使用者將來可能導航到的給定路由的元件。這確保了元件更早可用,並且不太可能阻塞導航,從而提高了效能。
如果您正在使用
NuxtLink
元件,Nuxt 已經自動預載入了必要的路由。示例
在使用 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')
}
}
在伺服器上,
preloadRouteComponents
將不起作用。