Skip to content

Commit cb12233

Browse files
alexdlntaskylizard
authored andcommitted
fix: configure general rule for trailing slash (npmx-dev#649)
1 parent 65e91a9 commit cb12233

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Removes trailing slashes from URLs.
3+
*
4+
* This middleware only runs in development to maintain consistent behavior.
5+
* In production, Vercel handles this redirect via vercel.json.
6+
*
7+
* - /package/vue/ → /package/vue
8+
* - /docs/getting-started/?query=value → /docs/getting-started?query=value
9+
*/
10+
export default defineNuxtRouteMiddleware(to => {
11+
if (!import.meta.dev) return
12+
13+
if (to.path !== '/' && to.path.endsWith('/')) {
14+
return navigateTo(
15+
{
16+
path: to.path.slice(0, -1),
17+
query: to.query,
18+
hash: to.hash,
19+
},
20+
{ replace: true },
21+
)
22+
}
23+
})

vercel.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://openapi.vercel.sh/vercel.json",
3+
"trailingSlash": false,
34
"redirects": [
45
{
56
"source": "/",

0 commit comments

Comments
 (0)