Unverified Commit b1ce1b24 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

docs: fix skipTrailingSlashRedirect middleware example (#65220)

The example here only updates the pathname, but the redirect path is
determined by taking the `req.nextUrl` object and stringifying it, which
means it would return the wrong redirect location.

Closes NEXT-3260
parent cf0414d0
......@@ -541,8 +541,9 @@ export default async function middleware(req) {
!pathname.endsWith('/') &&
!pathname.match(/((?!\.well-known(?:\/.*)?)(?:[^/]+\/)*[^/]+\.\w+)/)
) {
req.nextUrl.pathname += '/'
return NextResponse.redirect(req.nextUrl)
return NextResponse.redirect(
new URL(`${req.nextUrl.pathname}/`, req.nextUrl)
)
}
}
```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment