defineRouteRules
ページレベルでハイブリッドレンダリングのルートルールを定義します。
使用方法
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`を設定する必要があります。