Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9184ddb1
Unverified
Commit
9184ddb1
authored
May 19, 2026
by
Hendrik Liebau
Committed by
GitHub
May 19, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[backport] Fix catch-all `router.query` corruption with `basePath` + `rewrites` (#93917)
Backports: - #93294
parent
3279f016
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
3 deletions
+68
-3
router.ts
packages/next/src/shared/lib/router/router.ts
+8
-3
middleware-dynamic-basepath-matcher-rewrites.test.ts
...ites/middleware-dynamic-basepath-matcher-rewrites.test.ts
+19
-0
middleware.js
...iddleware-dynamic-basepath-matcher-rewrites/middleware.js
+9
-0
next.config.js
...ddleware-dynamic-basepath-matcher-rewrites/next.config.js
+8
-0
[...path].tsx
...are-dynamic-basepath-matcher-rewrites/pages/[...path].tsx
+15
-0
index.tsx
...dleware-dynamic-basepath-matcher-rewrites/pages/index.tsx
+9
-0
No files found.
packages/next/src/shared/lib/router/router.ts
View file @
9184ddb1
...
@@ -227,9 +227,14 @@ function getMiddlewareData<T extends FetchDataOutput>(
...
@@ -227,9 +227,14 @@ function getMiddlewareData<T extends FetchDataOutput>(
const
parsedSource
=
getNextPathnameInfo
(
const
parsedSource
=
getNextPathnameInfo
(
parseRelativeUrl
(
source
).
pathname
,
parseRelativeUrl
(
source
).
pathname
,
{
{
nextConfig
:
process
.
env
.
__NEXT_HAS_REWRITES
// Pass basePath (and trailingSlash) so the basePath prefix is
?
undefined
// stripped before the `_next/data/` check, but omit `i18n` so the
:
nextConfig
,
// locale prefix is preserved here — the rewrite resolver below
// handles the locale-prefixed `as`.
nextConfig
:
{
basePath
:
nextConfig
.
basePath
,
trailingSlash
:
nextConfig
.
trailingSlash
,
},
parseData
:
true
,
parseData
:
true
,
}
}
)
)
...
...
test/e2e/middleware-dynamic-basepath-matcher-rewrites/middleware-dynamic-basepath-matcher-rewrites.test.ts
0 → 100644
View file @
9184ddb1
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
retry
}
from
'next-test-utils'
describe
(
'middleware-dynamic-basepath-matcher-rewrites'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'preserves router.query on client-side navigation to a catch-all page'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/docs'
)
await
browser
.
elementById
(
'catchall-link'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementById
(
'page-title'
).
text
()).
toBe
(
'CatchAll'
)
})
expect
(
await
browser
.
elementById
(
'query-path'
).
text
()).
toBe
(
'["first"]'
)
})
})
test/e2e/middleware-dynamic-basepath-matcher-rewrites/middleware.js
0 → 100644
View file @
9184ddb1
import
{
NextResponse
}
from
'next/server'
export
default
function
middleware
()
{
return
NextResponse
.
next
()
}
export
const
config
=
{
matcher
:
'/:path*'
,
}
test/e2e/middleware-dynamic-basepath-matcher-rewrites/next.config.js
0 → 100644
View file @
9184ddb1
module
.
exports
=
{
basePath
:
'/docs'
,
async
rewrites
()
{
// Any non-empty rewrites array sets __NEXT_HAS_REWRITES=true; this entry
// only exists to flip that build flag, it isn't expected to match.
return
[{
source
:
'/never-matched-rewrite'
,
destination
:
'/never'
}]
},
}
test/e2e/middleware-dynamic-basepath-matcher-rewrites/pages/[...path].tsx
0 → 100644
View file @
9184ddb1
import
{
useRouter
}
from
'next/router'
export
default
function
CatchAll
()
{
const
router
=
useRouter
()
return
(
<
div
>
<
h1
id=
"page-title"
>
CatchAll
</
h1
>
<
p
id=
"query-path"
>
{
JSON
.
stringify
(
router
.
query
.
path
)
}
</
p
>
</
div
>
)
}
export
async
function
getServerSideProps
()
{
return
{
props
:
{}
}
}
test/e2e/middleware-dynamic-basepath-matcher-rewrites/pages/index.tsx
0 → 100644
View file @
9184ddb1
import
Link
from
'next/link'
export
default
function
Home
()
{
return
(
<
Link
href=
"/first"
id=
"catchall-link"
>
Go to catchall
</
Link
>
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment