mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-21 16:09:52 +00:00
Merge c96bf6048e
into 160efe7a7f
This commit is contained in:
commit
fd25b58e8f
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -34,6 +34,7 @@ export type NuxtPage = {
|
||||
alias?: string[] | string
|
||||
redirect?: RouteLocationRaw
|
||||
children?: NuxtPage[]
|
||||
middleware?: string[] | string
|
||||
/**
|
||||
* Set the render mode.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user