Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 6bcd9cd

Browse files
authored
fix(nuxt): avoid directly importing vue-router inside <NuxtLayout> (#8421)
1 parent 6de1431 commit 6bcd9cd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/nuxt/src/app/components/layout.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { computed, defineComponent, h, inject, nextTick, onMounted, Ref, Transition, unref, VNode } from 'vue'
2-
import { RouteLocationNormalizedLoaded, useRoute as useVueRouterRoute } from 'vue-router'
2+
import type { RouteLocationNormalizedLoaded } from 'vue-router'
33
import { _wrapIf } from './utils'
44
import { useRoute } from '#app'
55
// @ts-ignore
6+
import { useRoute as useVueRouterRoute } from '#build/pages'
7+
// @ts-ignore
68
import layouts from '#build/layouts'
79
// @ts-ignore
810
import { appLayoutTransition as defaultLayoutTransition } from '#build/nuxt.config.mjs'

packages/nuxt/src/pages/module.ts

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export default defineNuxtModule({
2323
// Disable module (and use universal router) if pages dir do not exists or user has disabled it
2424
if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) {
2525
addPlugin(resolve(distDir, 'app/plugins/router'))
26+
// Add vue-router import for `<NuxtLayout>` integration
27+
addTemplate({
28+
filename: 'pages.mjs',
29+
getContents: () => 'export { useRoute } from \'#app\''
30+
})
2631
return
2732
}
2833

@@ -135,6 +140,12 @@ export default defineNuxtModule({
135140
}
136141
})
137142

143+
// Add vue-router import for `<NuxtLayout>` integration
144+
addTemplate({
145+
filename: 'pages.mjs',
146+
getContents: () => 'export { useRoute } from \'vue-router\''
147+
})
148+
138149
// Add router options template
139150
addTemplate({
140151
filename: 'router.options.mjs',

0 commit comments

Comments
 (0)