mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
fix(nuxt3): child routes in vue-router don't have component field (#998)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
a3058eebae
commit
c5920c21e7
@ -6,6 +6,12 @@
|
|||||||
<NuxtLink to="/about">
|
<NuxtLink to="/about">
|
||||||
About
|
About
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
<NuxtLink to="/parent">
|
||||||
|
Parent (index)
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink to="/parent/b">
|
||||||
|
Parent (b)
|
||||||
|
</NuxtLink>
|
||||||
|
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</div>
|
</div>
|
||||||
|
6
examples/with-pages/pages/parent.vue
Normal file
6
examples/with-pages/pages/parent.vue
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Parent
|
||||||
|
<RouterView />
|
||||||
|
</div>
|
||||||
|
</template>
|
5
examples/with-pages/pages/parent/b.vue
Normal file
5
examples/with-pages/pages/parent/b.vue
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Parent/b
|
||||||
|
</div>
|
||||||
|
</template>
|
5
examples/with-pages/pages/parent/index.vue
Normal file
5
examples/with-pages/pages/parent/index.vue
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Parent/index
|
||||||
|
</div>
|
||||||
|
</template>
|
@ -2,7 +2,7 @@ import { existsSync } from 'fs'
|
|||||||
import { defineNuxtModule, addTemplate, addPlugin } from '@nuxt/kit'
|
import { defineNuxtModule, addTemplate, addPlugin } from '@nuxt/kit'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { distDir } from '../dirs'
|
import { distDir } from '../dirs'
|
||||||
import { resolveLayouts, resolvePagesRoutes } from './utils'
|
import { resolveLayouts, resolvePagesRoutes, addComponentToRoutes } from './utils'
|
||||||
|
|
||||||
export default defineNuxtModule({
|
export default defineNuxtModule({
|
||||||
name: 'router',
|
name: 'router',
|
||||||
@ -40,7 +40,7 @@ export default defineNuxtModule({
|
|||||||
filename: 'routes.mjs',
|
filename: 'routes.mjs',
|
||||||
async getContents () {
|
async getContents () {
|
||||||
const routes = await resolvePagesRoutes(nuxt)
|
const routes = await resolvePagesRoutes(nuxt)
|
||||||
const serializedRoutes = routes.map(route => ({ ...route, component: `{() => import('${route.file}')}` }))
|
const serializedRoutes = addComponentToRoutes(routes)
|
||||||
return `export default ${JSON.stringify(serializedRoutes, null, 2).replace(/"{(.+)}"/g, '$1')}`
|
return `export default ${JSON.stringify(serializedRoutes, null, 2).replace(/"{(.+)}"/g, '$1')}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -230,3 +230,11 @@ export async function resolveLayouts (nuxt: Nuxt) {
|
|||||||
return { name, file }
|
return { name, file }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addComponentToRoutes (routes: NuxtRoute[]) {
|
||||||
|
return routes.map(route => ({
|
||||||
|
...route,
|
||||||
|
children: addComponentToRoutes(route.children),
|
||||||
|
component: `{() => import('${route.file}')}`
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user