File tree Expand file tree Collapse file tree
packages/next/src/shared/lib/router
test/e2e/middleware-dynamic-basepath-matcher-rewrites Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -227,9 +227,14 @@ function getMiddlewareData<T extends FetchDataOutput>(
227227 const parsedSource = getNextPathnameInfo (
228228 parseRelativeUrl ( source ) . pathname ,
229229 {
230- nextConfig : process . env . __NEXT_HAS_REWRITES
231- ? undefined
232- : nextConfig ,
230+ // Pass basePath (and trailingSlash) so the basePath prefix is
231+ // stripped before the `_next/data/` check, but omit `i18n` so the
232+ // locale prefix is preserved here — the rewrite resolver below
233+ // handles the locale-prefixed `as`.
234+ nextConfig : {
235+ basePath : nextConfig . basePath ,
236+ trailingSlash : nextConfig . trailingSlash ,
237+ } ,
233238 parseData : true ,
234239 }
235240 )
Original file line number Diff line number Diff line change 1+ import { nextTestSetup } from 'e2e-utils'
2+ import { retry } from 'next-test-utils'
3+
4+ describe ( 'middleware-dynamic-basepath-matcher-rewrites' , ( ) => {
5+ const { next } = nextTestSetup ( {
6+ files : __dirname ,
7+ } )
8+
9+ it ( 'preserves router.query on client-side navigation to a catch-all page' , async ( ) => {
10+ const browser = await next . browser ( '/docs' )
11+ await browser . elementById ( 'catchall-link' ) . click ( )
12+
13+ await retry ( async ( ) => {
14+ expect ( await browser . elementById ( 'page-title' ) . text ( ) ) . toBe ( 'CatchAll' )
15+ } )
16+
17+ expect ( await browser . elementById ( 'query-path' ) . text ( ) ) . toBe ( '["first"]' )
18+ } )
19+ } )
Original file line number Diff line number Diff line change 1+ import { NextResponse } from 'next/server'
2+
3+ export default function middleware ( ) {
4+ return NextResponse . next ( )
5+ }
6+
7+ export const config = {
8+ matcher : '/:path*' ,
9+ }
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ basePath : '/docs' ,
3+ async rewrites ( ) {
4+ // Any non-empty rewrites array sets __NEXT_HAS_REWRITES=true; this entry
5+ // only exists to flip that build flag, it isn't expected to match.
6+ return [ { source : '/never-matched-rewrite' , destination : '/never' } ]
7+ } ,
8+ }
Original file line number Diff line number Diff line change 1+ import { useRouter } from 'next/router'
2+
3+ export default function CatchAll ( ) {
4+ const router = useRouter ( )
5+ return (
6+ < div >
7+ < h1 id = "page-title" > CatchAll</ h1 >
8+ < p id = "query-path" > { JSON . stringify ( router . query . path ) } </ p >
9+ </ div >
10+ )
11+ }
12+
13+ export async function getServerSideProps ( ) {
14+ return { props : { } }
15+ }
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function Home ( ) {
4+ return (
5+ < Link href = "/first" id = "catchall-link" >
6+ Go to catchall
7+ </ Link >
8+ )
9+ }
You can’t perform that action at this time.
0 commit comments