mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
feat(nuxt): allow extending routes with custom alias (#7074)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
parent
74db9d525e
commit
4bd1be9174
@ -232,11 +232,17 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
|
|||||||
const file = normalize(route.file)
|
const file = normalize(route.file)
|
||||||
const metaImportName = genSafeVariableName(file) + 'Meta'
|
const metaImportName = genSafeVariableName(file) + 'Meta'
|
||||||
metaImports.add(genImport(`${file}?macro=true`, [{ name: 'meta', as: metaImportName }]))
|
metaImports.add(genImport(`${file}?macro=true`, [{ name: 'meta', as: metaImportName }]))
|
||||||
|
|
||||||
|
let aliasCode = `${metaImportName}?.alias || []`
|
||||||
|
if (Array.isArray(route.alias) && route.alias.length) {
|
||||||
|
aliasCode = `${JSON.stringify(route.alias)}.concat(${aliasCode})`
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...Object.fromEntries(Object.entries(route).map(([key, value]) => [key, JSON.stringify(value)])),
|
...Object.fromEntries(Object.entries(route).map(([key, value]) => [key, JSON.stringify(value)])),
|
||||||
children: route.children ? normalizeRoutes(route.children, metaImports).routes : [],
|
children: route.children ? normalizeRoutes(route.children, metaImports).routes : [],
|
||||||
meta: route.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(route.meta)}}` : metaImportName,
|
meta: route.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(route.meta)}}` : metaImportName,
|
||||||
alias: `${metaImportName}?.alias || []`,
|
alias: aliasCode,
|
||||||
component: genDynamicImport(file, { interopDefault: true })
|
component: genDynamicImport(file, { interopDefault: true })
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
@ -42,6 +42,7 @@ export type NuxtPage = {
|
|||||||
path: string
|
path: string
|
||||||
file: string
|
file: string
|
||||||
meta?: Record<string, any>
|
meta?: Record<string, any>
|
||||||
|
alias?: string[]
|
||||||
children?: NuxtPage[]
|
children?: NuxtPage[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user