mirror of https://github.com/nuxt/nuxt.git
fix(nuxt): properly handle query for component wrapper (#20591)
This commit is contained in:
parent
a13b18eddf
commit
d2fc6ae614
|
@ -21,15 +21,19 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
|
||||||
function getComponentsImports (): Import[] {
|
function getComponentsImports (): Import[] {
|
||||||
const components = getComponents(mode)
|
const components = getComponents(mode)
|
||||||
return components.flatMap((c): Import[] => {
|
return components.flatMap((c): Import[] => {
|
||||||
|
const withMode = (mode: string | undefined) => mode
|
||||||
|
? `${c.filePath}${c.filePath.includes('?') ? '&' : '?'}nuxt_component=${mode}`
|
||||||
|
: c.filePath
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
as: c.pascalName,
|
as: c.pascalName,
|
||||||
from: c.filePath + (c.mode === 'client' ? '?component=client' : ''),
|
from: withMode(c.mode === 'client' ? 'client' : undefined),
|
||||||
name: 'default'
|
name: 'default'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
as: 'Lazy' + c.pascalName,
|
as: 'Lazy' + c.pascalName,
|
||||||
from: c.filePath + '?component=' + [c.mode === 'client' ? 'client' : '', 'async'].filter(Boolean).join(','),
|
from: withMode([c.mode === 'client' ? 'client' : '', 'async'].filter(Boolean).join(',')),
|
||||||
name: 'default'
|
name: 'default'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -43,10 +47,10 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
|
||||||
},
|
},
|
||||||
async transform (code, id) {
|
async transform (code, id) {
|
||||||
// Virtual component wrapper
|
// Virtual component wrapper
|
||||||
if (id.includes('?component')) {
|
if (id.match(/[?&]nuxt_component=/)) {
|
||||||
const { search } = parseURL(id)
|
const { search } = parseURL(id)
|
||||||
const query = parseQuery(search)
|
const query = parseQuery(search)
|
||||||
const mode = query.component
|
const mode = query.nuxt_component
|
||||||
const bare = id.replace(/\?.*/, '')
|
const bare = id.replace(/\?.*/, '')
|
||||||
if (mode === 'async') {
|
if (mode === 'async') {
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue