mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): remove undefined keys in route object (#25667)
This commit is contained in:
parent
e317349688
commit
4f3391fc0a
@ -139,8 +139,8 @@ const pageContentsCache: Record<string, string> = {}
|
|||||||
const metaCache: Record<string, Partial<Record<keyof NuxtPage, any>>> = {}
|
const metaCache: Record<string, Partial<Record<keyof NuxtPage, any>>> = {}
|
||||||
async function getRouteMeta (contents: string, absolutePath: string): Promise<Partial<Record<keyof NuxtPage, any>>> {
|
async function getRouteMeta (contents: string, absolutePath: string): Promise<Partial<Record<keyof NuxtPage, any>>> {
|
||||||
// set/update pageContentsCache, invalidate metaCache on cache mismatch
|
// set/update pageContentsCache, invalidate metaCache on cache mismatch
|
||||||
if (!(absolutePath in pageContentsCache) || pageContentsCache[absolutePath] !== contents) {
|
if (!(absolutePath in pageContentsCache) || pageContentsCache[absolutePath] !== contents) {
|
||||||
pageContentsCache[absolutePath] = contents
|
pageContentsCache[absolutePath] = contents
|
||||||
delete metaCache[absolutePath]
|
delete metaCache[absolutePath]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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": [
|
||||||
|
@ -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": [
|
||||||
|
8
test/fixtures/basic/nuxt.config.ts
vendored
8
test/fixtures/basic/nuxt.config.ts
vendored
@ -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 => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user