fix(nuxt): avoid vue-router warning with routeRule redirect (#25391)

This commit is contained in:
Daniel Roe 2024-01-29 11:07:52 +00:00 committed by GitHub
parent 034d1aaa6f
commit b5853c977e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import { existsSync, readdirSync } from 'node:fs' import { existsSync, readdirSync } from 'node:fs'
import { mkdir, readFile } from 'node:fs/promises' import { mkdir, readFile } from 'node:fs/promises'
import { addBuildPlugin, addComponent, addPlugin, addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, findPath, logger, updateTemplates } from '@nuxt/kit' import { addBuildPlugin, addComponent, addPlugin, addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, findPath, logger, updateTemplates, useNitro } from '@nuxt/kit'
import { dirname, join, relative, resolve } from 'pathe' import { dirname, join, relative, resolve } from 'pathe'
import { genImport, genObjectFromRawEntries, genString } from 'knitwork' import { genImport, genObjectFromRawEntries, genString } from 'knitwork'
import { joinURL } from 'ufo' import { joinURL } from 'ufo'
@ -337,6 +337,22 @@ export default defineNuxtModule({
}) })
} }
if (nuxt.options.experimental.appManifest) {
// Add all redirect paths as valid routes to router; we will handle these in a client-side middleware
// when the app manifest is enabled.
nuxt.hook('pages:extend', routes => {
const nitro = useNitro()
for (const path in nitro.options.routeRules) {
const rule = nitro.options.routeRules[path]
if (!rule.redirect) { continue }
routes.push({
path: path.replace(/\/[^/]*\*\*/, '/:pathMatch(.*)'),
file: resolve(runtimeDir, 'component-stub'),
})
}
})
}
// Extract macros from pages // Extract macros from pages
const pageMetaOptions: PageMetaPluginOptions = { const pageMetaOptions: PageMetaPluginOptions = {
dev: nuxt.options.dev, dev: nuxt.options.dev,

View File

@ -0,0 +1 @@
export default {}