defineRouteRules

原始檔
在頁面級別定義混合渲染的路由規則。
此功能是實驗性的,要使用它,您必須在 nuxt.config 中啟用 experimental.inlineRouteRules 選項。

使用

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 中設定了自定義 pathalias,您應該直接在 nuxt.config 中設定 routeRules

閱讀更多關於 routeRules 的資訊。