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

This commit is contained in:
Daniel Roe 2024-07-11 09:06:25 +01:00
parent 3412f87276
commit c2e843485c
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
1 changed files with 8 additions and 0 deletions

View File

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