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/**
请求。
为了获得更多控制,例如使用自定义的 path
或在页面的 definePageMeta
中设置的 alias
,您应直接在 nuxt.config
中设置 routeRules
。