diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index 4c6fa9c07e..bb47ea4b17 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -249,12 +249,12 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ if (isAppManifestEnabled) { const routeRules = await nuxtApp.runWithContext(() => getRouteRules(to.path)) - if (routeRules.nuxtMiddleware) { - for (const key in routeRules.nuxtMiddleware) { + if (routeRules.appMiddleware) { + for (const key in routeRules.appMiddleware) { const guard = nuxtApp._middleware.named[key] as RouteGuard | undefined if (!guard) { return } - if (routeRules.nuxtMiddleware[key]) { + if (routeRules.appMiddleware[key]) { middlewareEntries.add(guard) } else { middlewareEntries.delete(guard) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 87d3da4bba..e03b560e0b 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -267,16 +267,16 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { nuxt.hook('nitro:config', (config) => { const rules = config.routeRules for (const rule in rules) { - if (!(rules[rule] as any).nuxtMiddleware) { continue } - const value = (rules[rule] as any).nuxtMiddleware + if (!(rules[rule] as any).appMiddleware) { continue } + const value = (rules[rule] as any).appMiddleware if (typeof value === 'string') { - (rules[rule] as NitroOptions['routeRules']).nuxtMiddleware = { [value]: true } + (rules[rule] as NitroOptions['routeRules']).appMiddleware = { [value]: true } } else if (Array.isArray(value)) { const normalizedRules: Record = {} for (const middleware of value) { normalizedRules[middleware] = true } - (rules[rule] as NitroOptions['routeRules']).nuxtMiddleware = normalizedRules + (rules[rule] as NitroOptions['routeRules']).appMiddleware = normalizedRules } } }) @@ -291,7 +291,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const filteredRules = {} as Record for (const routeKey in _routeRules[key]) { const value = (_routeRules as any)[key][routeKey] - if (['prerender', 'redirect', 'nuxtMiddleware'].includes(routeKey) && value) { + if (['prerender', 'redirect', 'appMiddleware'].includes(routeKey) && value) { if (routeKey === 'redirect') { filteredRules[routeKey] = typeof value === 'string' ? value : value.to } else { diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 62b33f02cd..fc33188e2e 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -244,7 +244,7 @@ declare module 'nitropack' { interface NitroRouteRules { ssr?: boolean experimentalNoScripts?: boolean - nuxtMiddleware?: Record + appMiddleware?: Record } interface NitroRuntimeHooks { 'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 3b6be825f3..4ddb48d077 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -477,7 +477,7 @@ export default defineNuxtModule({ '}', 'declare module \'nitropack\' {', ' interface NitroRouteConfig {', - ' nuxtMiddleware?: MiddlewareKey | MiddlewareKey[] | Record', + ' appMiddleware?: MiddlewareKey | MiddlewareKey[] | Record', ' }', '}' ].join('\n') diff --git a/packages/nuxt/src/pages/runtime/plugins/router.ts b/packages/nuxt/src/pages/runtime/plugins/router.ts index ad27599a6f..a53a73dab6 100644 --- a/packages/nuxt/src/pages/runtime/plugins/router.ts +++ b/packages/nuxt/src/pages/runtime/plugins/router.ts @@ -179,9 +179,9 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({ if (isAppManifestEnabled) { const routeRules = await nuxtApp.runWithContext(() => getRouteRules(to.path)) - if (routeRules.nuxtMiddleware) { - for (const key in routeRules.nuxtMiddleware) { - if (routeRules.nuxtMiddleware[key]) { + if (routeRules.appMiddleware) { + for (const key in routeRules.appMiddleware) { + if (routeRules.appMiddleware[key]) { middlewareEntries.add(key) } else { middlewareEntries.delete(key) diff --git a/packages/nuxt/types.d.mts b/packages/nuxt/types.d.mts index cdfd68e043..043bf0c49e 100644 --- a/packages/nuxt/types.d.mts +++ b/packages/nuxt/types.d.mts @@ -26,7 +26,7 @@ declare module 'nitropack' { interface NitroRouteRules { ssr?: boolean experimentalNoScripts?: boolean - nuxtMiddleware?: Record + appMiddleware?: Record } interface NitroRuntimeHooks { 'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise diff --git a/packages/nuxt/types.d.ts b/packages/nuxt/types.d.ts index 23ca5b4ff8..1733bdec62 100644 --- a/packages/nuxt/types.d.ts +++ b/packages/nuxt/types.d.ts @@ -26,7 +26,7 @@ declare module 'nitropack' { interface NitroRouteRules { ssr?: boolean experimentalNoScripts?: boolean - nuxtMiddleware?: Record + appMiddleware?: Record } interface NitroRuntimeHooks { 'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 5231b0dbed..61851c2373 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -60,7 +60,7 @@ export default defineNuxtConfig({ }, routeRules: { '/route-rules/spa': { ssr: false }, - '/route-rules/middleware': { nuxtMiddleware: 'route-rules-middleware' }, + '/route-rules/middleware': { appMiddleware: 'route-rules-middleware' }, '/hydration/spa-redirection/**': { ssr: false }, '/no-scripts': { experimentalNoScripts: true } },