Skip to content

Commit

Permalink
fix(nuxt): add type support for router composables without pages/ i…
Browse files Browse the repository at this point in the history
…ntegration
  • Loading branch information
danielroe committed May 22, 2023
1 parent 2518cf8 commit 397c54c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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'

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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') })
Expand Down

1 comment on commit 397c54c

@Poutou7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand,
The pages file I created for rounting is not responding to nuxt3.5.2
What is the alternative and what is the new way of routing?
Thank you.

Please sign in to comment.