From e18a61552b7936365ab9473189919b1672ed803b Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:42:37 -0700 Subject: [PATCH] docs: fix skipTrailingSlashRedirect middleware example --- .../01-routing/14-middleware.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/02-app/01-building-your-application/01-routing/14-middleware.mdx b/docs/02-app/01-building-your-application/01-routing/14-middleware.mdx index 456d699d6803c..ddee8ad7b966b 100644 --- a/docs/02-app/01-building-your-application/01-routing/14-middleware.mdx +++ b/docs/02-app/01-building-your-application/01-routing/14-middleware.mdx @@ -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) + ) } } ```