From c2e843485c34c87d972565f476c189590aa6fea3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 11 Jul 2024 09:06:25 +0100 Subject: [PATCH] fix(nuxt): use native vue-router composables (#28114) --- packages/nuxt/src/pages/module.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 4643c75e8b..18ed8c2014 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -218,6 +218,14 @@ export default defineNuxtModule({ references.push({ types: useExperimentalTypedPages ? 'vue-router/auto-routes' : 'vue-router' }) }) + // Add vue-router route guard imports + nuxt.hook('imports:sources', (sources) => { + const routerImports = sources.find(s => s.from === '#app/composables/router' && s.imports.includes('onBeforeRouteLeave')) + if (routerImports) { + routerImports.from = 'vue-router' + } + }) + // Regenerate templates when adding or removing pages const updateTemplatePaths = nuxt.options._layers.flatMap((l) => { const dir = (l.config.rootDir === nuxt.options.rootDir ? nuxt.options : l.config).dir