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 的信息。