Skip to content

Commit 570bce6

Browse files
committed
Ensure resolvedPathname normalizes trailing slash
1 parent 45a5405 commit 570bce6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/next/src/build/templates/pages.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ export async function handler(
225225
const method = req.method || 'GET'
226226

227227
const resolvedUrl = formatUrl({
228-
pathname: parsedUrl.pathname,
228+
pathname: nextConfig.trailingSlash
229+
? parsedUrl.pathname
230+
: removeTrailingSlash(parsedUrl.pathname || '/'),
229231
// make sure to only add query values from original URL
230232
query: hasStaticProps ? {} : originalQuery,
231233
})

packages/next/src/server/route-modules/route-module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
type RouterServerContext,
6060
} from '../lib/router-utils/router-server-context'
6161
import { decodePathParams } from '../lib/router-utils/decode-path-params'
62+
import { removeTrailingSlash } from '../../shared/lib/router/utils/remove-trailing-slash'
6263

6364
/**
6465
* RouteModuleOptions is the options that are passed to the route module, other
@@ -782,6 +783,8 @@ export abstract class RouteModule<
782783
resolvedPathname = decodePathParams(resolvedPathname)
783784
} catch (_) {}
784785

786+
resolvedPathname = removeTrailingSlash(resolvedPathname)
787+
785788
return {
786789
query,
787790
originalQuery,

0 commit comments

Comments
 (0)