fix(nuxt): respect existing props value in definePageMeta (#29683)

This commit is contained in:
xjccc 2024-11-03 07:38:54 +08:00 committed by GitHub
parent 2aa4daab92
commit cbafa582a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View File

@ -507,13 +507,14 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
const route: NormalizedRoute = { const route: NormalizedRoute = {
path: serializeRouteValue(page.path), path: serializeRouteValue(page.path),
props: serializeRouteValue(page.props),
name: serializeRouteValue(page.name), name: serializeRouteValue(page.name),
meta: serializeRouteValue(metaFiltered, skipMeta), meta: serializeRouteValue(metaFiltered, skipMeta),
alias: serializeRouteValue(toArray(page.alias), skipAlias), alias: serializeRouteValue(toArray(page.alias), skipAlias),
redirect: serializeRouteValue(page.redirect), redirect: serializeRouteValue(page.redirect),
} }
for (const key of ['path', 'name', 'meta', 'alias', 'redirect'] satisfies NormalizedRouteKeys) { for (const key of ['path', 'props', 'name', 'meta', 'alias', 'redirect'] satisfies NormalizedRouteKeys) {
if (route[key] === undefined) { if (route[key] === undefined) {
delete route[key] delete route[key]
} }
@ -542,7 +543,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
const metaRoute: NormalizedRoute = { const metaRoute: NormalizedRoute = {
name: `${metaImportName}?.name ?? ${route.name}`, name: `${metaImportName}?.name ?? ${route.name}`,
path: `${metaImportName}?.path ?? ${route.path}`, path: `${metaImportName}?.path ?? ${route.path}`,
props: `${metaImportName}?.props ?? false`, props: `${metaImportName}?.props ?? ${route.props ?? false}`,
meta: `${metaImportName} || {}`, meta: `${metaImportName} || {}`,
alias: `${metaImportName}?.alias || []`, alias: `${metaImportName}?.alias || []`,
redirect: `${metaImportName}?.redirect`, redirect: `${metaImportName}?.redirect`,

View File

@ -36,7 +36,7 @@
"meta": "mockMeta || {}", "meta": "mockMeta || {}",
"name": "mockMeta?.name ?? "page-with-props"", "name": "mockMeta?.name ?? "page-with-props"",
"path": "mockMeta?.path ?? "/page-with-props"", "path": "mockMeta?.path ?? "/page-with-props"",
"props": "mockMeta?.props ?? false", "props": "mockMeta?.props ?? true",
"redirect": "mockMeta?.redirect", "redirect": "mockMeta?.redirect",
}, },
], ],

View File

@ -29,6 +29,7 @@
"component": "() => import("pages/page-with-props.vue")", "component": "() => import("pages/page-with-props.vue")",
"name": ""page-with-props"", "name": ""page-with-props"",
"path": ""/page-with-props"", "path": ""/page-with-props"",
"props": "true",
}, },
], ],
"should allow pages with `:` in their path": [ "should allow pages with `:` in their path": [