This commit is contained in:
Saeid Zareie 2025-02-18 11:13:51 +01:00 committed by GitHub
commit fd25b58e8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 4 deletions

View File

@ -332,7 +332,7 @@ globalThis.Buffer = globalThis.Buffer || Buffer
## scanPageMeta
This option allows exposing some route metadata defined in `definePageMeta` at build-time to modules (specifically `alias`, `name`, `path`, `redirect`).
This option allows exposing some route metadata defined in `definePageMeta` at build-time to modules (specifically `alias`, `name`, `path`, `redirect`, `props` and `middleware`).
This only works with static or strings/arrays rather than variables or conditional assignment. See [original issue](https://github.com/nuxt/nuxt/issues/24770) for more information and context.

View File

@ -202,7 +202,7 @@ export function extractScriptContent (sfc: string) {
}
const PAGE_META_RE = /definePageMeta\([\s\S]*?\)/
const defaultExtractionKeys = ['name', 'path', 'props', 'alias', 'redirect'] as const
const defaultExtractionKeys = ['name', 'path', 'props', 'alias', 'redirect', 'middleware'] as const
const DYNAMIC_META_KEY = '__nuxt_dynamic_meta_key' as const
const pageContentsCache: Record<string, string> = {}
@ -254,6 +254,10 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr
if (!property) { continue }
const propertyValue = withLocations(property.value)
if (key === 'middleware') {
dynamicProperties.add('meta')
}
if (propertyValue.type === 'ObjectExpression') {
const valueString = js.code.slice(propertyValue.start, propertyValue.end)

View File

@ -124,9 +124,11 @@ definePageMeta({ name: 'bar' })
"meta": {
"__nuxt_dynamic_meta_key": Set {
"props",
"middleware",
"meta",
},
},
"middleware": [],
"name": "some-custom-name",
"path": "/some-custom-path",
"props": {
@ -162,9 +164,11 @@ definePageMeta({ name: 'bar' })
{
"meta": {
"__nuxt_dynamic_meta_key": Set {
"middleware",
"meta",
},
},
"middleware": [],
"name": "some-custom-name",
"path": "/some-custom-path",
}
@ -190,7 +194,7 @@ definePageMeta({ name: 'bar' })
{
"meta": {
"__nuxt_dynamic_meta_key": Set {
"meta",
"middleware",
},
},
"name": "some-custom-name",

View File

@ -325,7 +325,7 @@ export default defineResolvers({
inlineRouteRules: false,
/**
* Allow exposing some route metadata defined in `definePageMeta` at build-time to modules (alias, name, path, redirect).
* Allow exposing some route metadata defined in `definePageMeta` at build-time to modules (alias, name, path, redirect, props, middleware).
*
* This only works with static or strings/arrays rather than variables or conditional assignment.
*

View File

@ -34,6 +34,7 @@ export type NuxtPage = {
alias?: string[] | string
redirect?: RouteLocationRaw
children?: NuxtPage[]
middleware?: string[] | string
/**
* Set the render mode.
*