mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +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 metaImportName = genSafeVariableName(file) + 'Meta'
|
||||
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 {
|
||||
...Object.fromEntries(Object.entries(route).map(([key, value]) => [key, JSON.stringify(value)])),
|
||||
children: route.children ? normalizeRoutes(route.children, metaImports).routes : [],
|
||||
meta: route.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(route.meta)}}` : metaImportName,
|
||||
alias: `${metaImportName}?.alias || []`,
|
||||
alias: aliasCode,
|
||||
component: genDynamicImport(file, { interopDefault: true })
|
||||
}
|
||||
}))
|
||||
|
@ -42,6 +42,7 @@ export type NuxtPage = {
|
||||
path: string
|
||||
file: string
|
||||
meta?: Record<string, any>
|
||||
alias?: string[]
|
||||
children?: NuxtPage[]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user