defineRouteRules
在頁面級別定義混合渲染的路由規則。
使用
app/pages/index.vue
<script setup lang="ts">
defineRouteRules({
prerender: true,
})
</script>
<template>
<h1>Hello world!</h1>
</template>
將被翻譯為
nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/': { prerender: true },
},
})
執行
nuxt build
時,主頁將預渲染到 .output/public/index.html
並進行靜態服務。注意事項
- 在
~/pages/foo/bar.vue
中定義的規則將應用於/foo/bar
請求。 - 在
~/pages/foo/[id].vue
中的規則將應用於/foo/**
請求。
為了獲得更多控制,例如如果您在頁面的 definePageMeta
中設定了自定義 path
或 alias
,您應該直接在 nuxt.config
中設定 routeRules
。