diff --git a/app/middleware/trailing-slash.global.ts b/app/middleware/trailing-slash.global.ts new file mode 100644 index 000000000..f0386e923 --- /dev/null +++ b/app/middleware/trailing-slash.global.ts @@ -0,0 +1,23 @@ +/** + * Removes trailing slashes from URLs. + * + * This middleware only runs in development to maintain consistent behavior. + * In production, Vercel handles this redirect via vercel.json. + * + * - /package/vue/ → /package/vue + * - /docs/getting-started/?query=value → /docs/getting-started?query=value + */ +export default defineNuxtRouteMiddleware(to => { + if (!import.meta.dev) return + + if (to.path !== '/' && to.path.endsWith('/')) { + return navigateTo( + { + path: to.path.slice(0, -1), + query: to.query, + hash: to.hash, + }, + { replace: true }, + ) + } +}) diff --git a/vercel.json b/vercel.json index 47cb5701d..602fb126a 100644 --- a/vercel.json +++ b/vercel.json @@ -1,5 +1,6 @@ { "$schema": "https://openapi.vercel.sh/vercel.json", + "trailingSlash": false, "redirects": [ { "source": "/",