mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): preserve route-specific metadata on route.meta
(#28441)
This commit is contained in:
parent
4354d31090
commit
89ce936b45
@ -198,6 +198,31 @@ export default defineNuxtConfig({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Deduplication of Route Metadata
|
||||||
|
|
||||||
|
🚦 **Impact Level**: Minimal
|
||||||
|
|
||||||
|
##### What Changed
|
||||||
|
|
||||||
|
It's possible to set some route metadata using `definePageMeta`, such as the `name`, `path`, and so on. Previously these were available both on the route and on route metadata (for example, `route.name` and `route.meta.name`).
|
||||||
|
|
||||||
|
Now, they are only accessible on the route object.
|
||||||
|
|
||||||
|
##### Reasons for Change
|
||||||
|
|
||||||
|
This is a result of enabling `experimental.scanPageMeta` by default, and is a performance optimization.
|
||||||
|
|
||||||
|
##### Migration Steps
|
||||||
|
|
||||||
|
The migration should be straightforward:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
- console.log(route.meta.name)
|
||||||
|
+ console.log(route.name)
|
||||||
|
```
|
||||||
|
|
||||||
#### Shared Prerender Data
|
#### Shared Prerender Data
|
||||||
|
|
||||||
🚦 **Impact Level**: Medium
|
🚦 **Impact Level**: Medium
|
||||||
|
@ -279,7 +279,7 @@ export async function getRouteMeta (contents: string, absolutePath: string): Pro
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const name = property.key.type === 'Identifier' ? property.key.name : String(property.value)
|
const name = property.key.type === 'Identifier' ? property.key.name : String(property.value)
|
||||||
if (!(extractionKeys as unknown as string[]).includes(name)) {
|
if (name) {
|
||||||
dynamicProperties.add('meta')
|
dynamicProperties.add('meta')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -329,6 +329,7 @@
|
|||||||
"should properly override route name if definePageMeta name override is defined.": [
|
"should properly override route name if definePageMeta name override is defined.": [
|
||||||
{
|
{
|
||||||
"component": "() => import("pages/index.vue").then(m => m.default || m)",
|
"component": "() => import("pages/index.vue").then(m => m.default || m)",
|
||||||
|
"meta": "mockMeta || {}",
|
||||||
"name": ""home"",
|
"name": ""home"",
|
||||||
"path": ""/"",
|
"path": ""/"",
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,10 @@ describe('page metadata', () => {
|
|||||||
for (const ext of ['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs']) {
|
for (const ext of ['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs']) {
|
||||||
const meta = await getRouteMeta(fileContents, `/app/pages/index.${ext}`)
|
const meta = await getRouteMeta(fileContents, `/app/pages/index.${ext}`)
|
||||||
expect(meta).toStrictEqual({
|
expect(meta).toStrictEqual({
|
||||||
name: 'bar',
|
'name': 'bar',
|
||||||
|
'meta': {
|
||||||
|
'__nuxt_dynamic_meta_key': new Set(['meta']),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -348,6 +348,7 @@ describe('pages:generateRoutesFromFiles', () => {
|
|||||||
name: 'home',
|
name: 'home',
|
||||||
path: '/',
|
path: '/',
|
||||||
file: `${pagesDir}/index.vue`,
|
file: `${pagesDir}/index.vue`,
|
||||||
|
meta: { [DYNAMIC_META_KEY]: new Set(['meta']) },
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user