From 397c54c9db8a6eeaeabff8ce06943e0881aac806 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 22 May 2023 14:48:08 +0100 Subject: [PATCH] fix(nuxt): add type support for router composables without `pages/` integration --- packages/nuxt/src/pages/module.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 46bbdab5ec..c3de3ab0ef 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -64,6 +64,14 @@ export default defineNuxtModule({ } }) + // adds support for #vue-router alias (used for types) with and without pages integration + addTemplate({ + filename: 'vue-router.d.ts', + getContents: () => `export * from '${useExperimentalTypedPages ? 'vue-router/auto' : 'vue-router'}'` + }) + + nuxt.options.alias['#vue-router'] = join(nuxt.options.buildDir, 'vue-router') + if (!nuxt.options.pages) { addPlugin(resolve(distDir, 'app/plugins/router')) addTemplate({ @@ -78,6 +86,12 @@ export default defineNuxtModule({ return } + addTemplate({ + filename: 'vue-router.mjs', + // TODO: use `vue-router/auto` when we have support for page metadata + getContents: () => 'export * from \'vue-router\';' + }) + if (useExperimentalTypedPages) { const declarationFile = './types/typed-router.d.ts' @@ -261,17 +275,6 @@ export default defineNuxtModule({ } }) - // adds support for #vue-router alias - addTemplate({ - filename: 'vue-router.mjs', - // TODO: use `vue-router/auto` when we have support for page metadata - getContents: () => 'export * from \'vue-router\';' - }) - addTemplate({ - filename: 'vue-router.d.ts', - getContents: () => `export * from '${useExperimentalTypedPages ? 'vue-router/auto' : 'vue-router'}'` - }) - // Add routes template addTemplate({ filename: 'routes.mjs', @@ -365,8 +368,6 @@ export default defineNuxtModule({ filePath: resolve(distDir, 'pages/runtime/page') }) - nuxt.options.alias['#vue-router'] = join(nuxt.options.buildDir, 'vue-router') - // Add declarations for middleware keys nuxt.hook('prepare:types', ({ references }) => { references.push({ path: resolve(nuxt.options.buildDir, 'types/middleware.d.ts') })