mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): remove absolute paths from routes objects (#9655)
This commit is contained in:
parent
050c6dfd8a
commit
23307cd8e0
@ -223,28 +223,34 @@ function prepareRoutes (routes: NuxtPage[], parent?: NuxtPage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> = new Set()): { imports: Set<string>, routes: string } {
|
export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> = new Set()): { imports: Set<string>, routes: string } {
|
||||||
|
const nuxt = useNuxt()
|
||||||
return {
|
return {
|
||||||
imports: metaImports,
|
imports: metaImports,
|
||||||
routes: genArrayFromRaw(routes.map((route) => {
|
routes: genArrayFromRaw(routes.map((page) => {
|
||||||
const file = normalize(route.file)
|
const file = normalize(page.file)
|
||||||
const metaImportName = genSafeVariableName(file) + 'Meta'
|
const metaImportName = genSafeVariableName(relative(nuxt.options.rootDir, file)) + 'Meta'
|
||||||
metaImports.add(genImport(`${file}?macro=true`, [{ name: 'default', as: metaImportName }]))
|
metaImports.add(genImport(`${file}?macro=true`, [{ name: 'default', as: metaImportName }]))
|
||||||
|
|
||||||
let aliasCode = `${metaImportName}?.alias || []`
|
let aliasCode = `${metaImportName}?.alias || []`
|
||||||
if (Array.isArray(route.alias) && route.alias.length) {
|
if (Array.isArray(page.alias) && page.alias.length) {
|
||||||
aliasCode = `${JSON.stringify(route.alias)}.concat(${aliasCode})`
|
aliasCode = `${JSON.stringify(page.alias)}.concat(${aliasCode})`
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const route = {
|
||||||
...Object.fromEntries(Object.entries(route).map(([key, value]) => [key, JSON.stringify(value)])),
|
...Object.fromEntries(Object.entries(page).map(([key, value]) => [key, JSON.stringify(value)])),
|
||||||
name: `${metaImportName}?.name ?? ${route.name ? JSON.stringify(route.name) : 'undefined'}`,
|
file: undefined,
|
||||||
path: `${metaImportName}?.path ?? ${JSON.stringify(route.path)}`,
|
name: `${metaImportName}?.name ?? ${page.name ? JSON.stringify(page.name) : 'undefined'}`,
|
||||||
children: route.children ? normalizeRoutes(route.children, metaImports).routes : [],
|
path: `${metaImportName}?.path ?? ${JSON.stringify(page.path)}`,
|
||||||
meta: route.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(route.meta)}}` : metaImportName,
|
children: page.children ? normalizeRoutes(page.children, metaImports).routes : [],
|
||||||
|
meta: page.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(page.meta)}}` : metaImportName,
|
||||||
alias: aliasCode,
|
alias: aliasCode,
|
||||||
redirect: route.redirect ? JSON.stringify(route.redirect) : `${metaImportName}?.redirect || undefined`,
|
redirect: page.redirect ? JSON.stringify(page.redirect) : `${metaImportName}?.redirect || undefined`,
|
||||||
component: genDynamicImport(file, { interopDefault: true })
|
component: genDynamicImport(file, { interopDefault: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete route.file
|
||||||
|
|
||||||
|
return route
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user