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

Commit

Permalink
fix(nuxt): avoid directly importing vue-router inside <NuxtLayout> (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 24, 2022
1 parent 6de1431 commit 6bcd9cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/nuxt/src/app/components/layout.ts
@@ -1,8 +1,10 @@
import { computed, defineComponent, h, inject, nextTick, onMounted, Ref, Transition, unref, VNode } from 'vue'
import { RouteLocationNormalizedLoaded, useRoute as useVueRouterRoute } from 'vue-router'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { _wrapIf } from './utils'
import { useRoute } from '#app'
// @ts-ignore
import { useRoute as useVueRouterRoute } from '#build/pages'
// @ts-ignore
import layouts from '#build/layouts'
// @ts-ignore
import { appLayoutTransition as defaultLayoutTransition } from '#build/nuxt.config.mjs'
Expand Down
11 changes: 11 additions & 0 deletions packages/nuxt/src/pages/module.ts
Expand Up @@ -23,6 +23,11 @@ export default defineNuxtModule({
// Disable module (and use universal router) if pages dir do not exists or user has disabled it
if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) {
addPlugin(resolve(distDir, 'app/plugins/router'))
// Add vue-router import for `<NuxtLayout>` integration
addTemplate({
filename: 'pages.mjs',
getContents: () => 'export { useRoute } from \'#app\''
})
return
}

Expand Down Expand Up @@ -135,6 +140,12 @@ export default defineNuxtModule({
}
})

// Add vue-router import for `<NuxtLayout>` integration
addTemplate({
filename: 'pages.mjs',
getContents: () => 'export { useRoute } from \'vue-router\''
})

// Add router options template
addTemplate({
filename: 'router.options.mjs',
Expand Down

0 comments on commit 6bcd9cd

Please sign in to comment.