mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-22 16:39:58 +00:00
Merge c96bf6048e
into 160efe7a7f
This commit is contained in:
commit
fd25b58e8f
@ -332,7 +332,7 @@ globalThis.Buffer = globalThis.Buffer || Buffer
|
|||||||
|
|
||||||
## scanPageMeta
|
## 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.
|
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 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 DYNAMIC_META_KEY = '__nuxt_dynamic_meta_key' as const
|
||||||
|
|
||||||
const pageContentsCache: Record<string, string> = {}
|
const pageContentsCache: Record<string, string> = {}
|
||||||
@ -255,6 +255,10 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr
|
|||||||
|
|
||||||
const propertyValue = withLocations(property.value)
|
const propertyValue = withLocations(property.value)
|
||||||
|
|
||||||
|
if (key === 'middleware') {
|
||||||
|
dynamicProperties.add('meta')
|
||||||
|
}
|
||||||
|
|
||||||
if (propertyValue.type === 'ObjectExpression') {
|
if (propertyValue.type === 'ObjectExpression') {
|
||||||
const valueString = js.code.slice(propertyValue.start, propertyValue.end)
|
const valueString = js.code.slice(propertyValue.start, propertyValue.end)
|
||||||
try {
|
try {
|
||||||
|
@ -124,9 +124,11 @@ definePageMeta({ name: 'bar' })
|
|||||||
"meta": {
|
"meta": {
|
||||||
"__nuxt_dynamic_meta_key": Set {
|
"__nuxt_dynamic_meta_key": Set {
|
||||||
"props",
|
"props",
|
||||||
|
"middleware",
|
||||||
"meta",
|
"meta",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"middleware": [],
|
||||||
"name": "some-custom-name",
|
"name": "some-custom-name",
|
||||||
"path": "/some-custom-path",
|
"path": "/some-custom-path",
|
||||||
"props": {
|
"props": {
|
||||||
@ -162,9 +164,11 @@ definePageMeta({ name: 'bar' })
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"__nuxt_dynamic_meta_key": Set {
|
"__nuxt_dynamic_meta_key": Set {
|
||||||
|
"middleware",
|
||||||
"meta",
|
"meta",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"middleware": [],
|
||||||
"name": "some-custom-name",
|
"name": "some-custom-name",
|
||||||
"path": "/some-custom-path",
|
"path": "/some-custom-path",
|
||||||
}
|
}
|
||||||
@ -190,7 +194,7 @@ definePageMeta({ name: 'bar' })
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"__nuxt_dynamic_meta_key": Set {
|
"__nuxt_dynamic_meta_key": Set {
|
||||||
"meta",
|
"middleware",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"name": "some-custom-name",
|
"name": "some-custom-name",
|
||||||
|
@ -325,7 +325,7 @@ export default defineResolvers({
|
|||||||
inlineRouteRules: false,
|
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.
|
* This only works with static or strings/arrays rather than variables or conditional assignment.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +34,7 @@ export type NuxtPage = {
|
|||||||
alias?: string[] | string
|
alias?: string[] | string
|
||||||
redirect?: RouteLocationRaw
|
redirect?: RouteLocationRaw
|
||||||
children?: NuxtPage[]
|
children?: NuxtPage[]
|
||||||
|
middleware?: string[] | string
|
||||||
/**
|
/**
|
||||||
* Set the render mode.
|
* Set the render mode.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user