Skip to content

Commit

Permalink
fix(nuxt): use native vue-router composables (nuxt#28114)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jul 11, 2024
1 parent 200fe48 commit 4ea8931
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,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
Expand Down

0 comments on commit 4ea8931

Please sign in to comment.