nuxt/no-page-meta-runtime-values
Disallow runtime context values inside definePageMeta at the eager level, which is extracted into a separate chunk at build time and runs before component setup.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
nuxt |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
useRoute() is evaluated immediately while building the definePageMeta object, although the macro hoists that metadata outside the setup runtime context.
<script setup lang="ts">
definePageMeta({ title: useRoute() });
</script>
Good
validate receives a callback, so its useRoute().params.id access is deferred until the callback runs. The rule distinguishes deferred function bodies from eager metadata values.
<script setup lang="ts">
definePageMeta({ validate: () => Boolean(useRoute().params.id) });
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"nuxt/no-page-meta-runtime-values": "error"
}
},
});
Then run vp run lint.