fix(nuxt): remove undefined keys in route object (#25667)

This commit is contained in:
Daniel Roe 2024-02-07 10:00:19 +00:00 committed by GitHub
parent e317349688
commit 4f3391fc0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View File

@ -414,6 +414,12 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
redirect: serializeRouteValue(page.redirect), redirect: serializeRouteValue(page.redirect),
} }
for (const key of ['path', 'name', 'meta', 'alias', 'redirect'] satisfies NormalizedRouteKeys) {
if (route[key] === undefined) {
delete route[key]
}
}
if (page.children?.length) { if (page.children?.length) {
route.children = normalizeRoutes(page.children, metaImports, overrideMeta).routes route.children = normalizeRoutes(page.children, metaImports, overrideMeta).routes
} }

View File

@ -15,7 +15,6 @@
"meta": "{"hello":"world"}", "meta": "{"hello":"world"}",
"name": ""home"", "name": ""home"",
"path": ""/"", "path": ""/"",
"redirect": undefined,
}, },
], ],
"should allow pages with `:` in their path": [ "should allow pages with `:` in their path": [

View File

@ -14,7 +14,6 @@
"meta": "{"hello":"world"}", "meta": "{"hello":"world"}",
"name": ""home"", "name": ""home"",
"path": ""/"", "path": ""/"",
"redirect": undefined,
}, },
], ],
"should allow pages with `:` in their path": [ "should allow pages with `:` in their path": [

View File

@ -100,6 +100,14 @@ export default defineNuxtConfig({
})) }))
addBuildPlugin(plugin) addBuildPlugin(plugin)
}, },
function (_options, nuxt) {
nuxt.hook('pages:extend', pages => {
pages.push({
path: '/manual-redirect',
redirect: '/',
})
})
},
function (_options, nuxt) { function (_options, nuxt) {
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2'] const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']
const stripLayout = (page: NuxtPage): NuxtPage => ({ const stripLayout = (page: NuxtPage): NuxtPage => ({