mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
perf(nuxt): use single iteration when normalising routes (#24946)
This commit is contained in:
parent
34b5299412
commit
e084ee7b3a
@ -303,11 +303,12 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
|
|||||||
return {
|
return {
|
||||||
imports: metaImports,
|
imports: metaImports,
|
||||||
routes: genArrayFromRaw(routes.map((page) => {
|
routes: genArrayFromRaw(routes.map((page) => {
|
||||||
const route = Object.fromEntries(
|
const route: Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string } = Object.create(null)
|
||||||
Object.entries(page)
|
for (const [key, value] of Object.entries(page)) {
|
||||||
.filter(([key, value]) => key !== 'file' && (Array.isArray(value) ? value.length : value))
|
if (key !== 'file' && (Array.isArray(value) ? value.length : value)) {
|
||||||
.map(([key, value]) => [key, JSON.stringify(value)])
|
route[key as Exclude<keyof NuxtPage, 'file'>] = JSON.stringify(value)
|
||||||
) as Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (page.children?.length) {
|
if (page.children?.length) {
|
||||||
route.children = normalizeRoutes(page.children, metaImports).routes
|
route.children = normalizeRoutes(page.children, metaImports).routes
|
||||||
|
Loading…
Reference in New Issue
Block a user