defineRouteRules

在页面级别定义混合渲染的路由规则。

:

Read more in Docs > Guide > Going Further > Experimental Features#inlinerouterules.

此功能处于实验阶段,要使用它,你必须在 nuxt.config 中启用 experimental.inlineRouteRules 选项。

¥This feature is experimental and in order to use it you must enable the experimental.inlineRouteRules option in your nuxt.config.

::

用法

¥Usage

pages/index.vue
<script setup lang="ts">
defineRouteRules({
  prerender: true
})
</script>

<template>
  <h1>Hello world!</h1>
</template>

将被翻译为:

¥Will be translated to:

nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    '/': { prerender: true }
  }
})
运行 nuxt build 时,主页将在 .output/public/index.html 中预渲染并以静态方式提供。

注意事项

¥Notes

  • ~/pages/foo/bar.vue 中定义的规则将应用于 /foo/bar 请求。
  • ~/pages/foo/[id].vue 中的规则将应用于 /foo/** 请求。

更多详情,请查看 path

¥For more control, such as if you are using a custom path or alias set in the page's definePageMeta, you should set routeRules directly within your nuxt.config.

:

Read more in Docs > Guide > Concepts > Rendering#hybrid Rendering.

了解更多关于 routeRules 的信息。

¥Read more about the routeRules.

::