fix(nuxt): use native vue-router composables (#28114)

This commit is contained in:
Daniel Roe 2024-07-11 09:06:25 +01:00 committed by GitHub
parent 200fe48829
commit 4ea89318df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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