diff --git a/packages/nuxt/src/app/components/layout.ts b/packages/nuxt/src/app/components/layout.ts index ae82998ddf..70b96a3c56 100644 --- a/packages/nuxt/src/app/components/layout.ts +++ b/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' diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 82cc710d84..2846e5f577 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -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 `` integration + addTemplate({ + filename: 'pages.mjs', + getContents: () => 'export { useRoute } from \'#app\'' + }) return } @@ -135,6 +140,12 @@ export default defineNuxtModule({ } }) + // Add vue-router import for `` integration + addTemplate({ + filename: 'pages.mjs', + getContents: () => 'export { useRoute } from \'vue-router\'' + }) + // Add router options template addTemplate({ filename: 'router.options.mjs',