File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed
open-next/src/core/routing
tests-unit/tests/core/routing Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @opennextjs/aws " : patch
3
+ " tests-unit " : patch
4
+ ---
5
+
6
+ fix dataRoutes omitting basePath in page router (#897 )
Original file line number Diff line number Diff line change @@ -381,8 +381,8 @@ export function fixDataPage(
381
381
buildId : string ,
382
382
) : InternalEvent | InternalResult {
383
383
const { rawPath, query } = internalEvent ;
384
- const dataPattern = ` ${ NextConfig . basePath ?? "" } /_next/data/ ${ buildId } ` ;
385
-
384
+ const basePath = NextConfig . basePath ?? "" ;
385
+ const dataPattern = ` ${ basePath } /_next/data/ ${ buildId } ` ;
386
386
// Return 404 for data requests that don't match the buildId
387
387
if ( rawPath . startsWith ( "/_next/data" ) && ! rawPath . startsWith ( dataPattern ) ) {
388
388
return {
@@ -397,9 +397,9 @@ export function fixDataPage(
397
397
}
398
398
399
399
if ( rawPath . startsWith ( dataPattern ) && rawPath . endsWith ( ".json" ) ) {
400
- const newPath = rawPath
400
+ const newPath = ` ${ basePath } ${ rawPath
401
401
. slice ( dataPattern . length , - ".json" . length )
402
- . replace ( / ^ \/ i n d e x $ / , "/" ) ;
402
+ . replace ( / ^ \/ i n d e x $ / , "/" ) } ` ;
403
403
query . __nextDataReq = "1" ;
404
404
405
405
return {
Original file line number Diff line number Diff line change @@ -598,18 +598,19 @@ describe("fixDataPage", () => {
598
598
} ) ;
599
599
600
600
it ( "should remove json extension from data requests (with base path) and add __nextDataReq to query" , ( ) => {
601
- NextConfig . basePath = "/base" ;
601
+ const mockBasePath = "/base" ;
602
+ NextConfig . basePath = mockBasePath ;
602
603
603
604
const event = createEvent ( {
604
- url : " https://on/base/ _next/data/abc/test/file.json?hello=world" ,
605
+ url : ` https://on${ mockBasePath } / _next/data/abc/test/file.json?hello=world` ,
605
606
} ) ;
606
607
607
608
const response = fixDataPage ( event , "abc" ) ;
608
609
609
610
expect ( response ) . toEqual ( {
610
611
...event ,
611
- rawPath : " /test/file" ,
612
- url : " https://on/test/file?hello=world&__nextDataReq=1" ,
612
+ rawPath : ` ${ mockBasePath } /test/file` ,
613
+ url : ` https://on${ mockBasePath } /test/file?hello=world&__nextDataReq=1` ,
613
614
} ) ;
614
615
615
616
NextConfig . basePath = undefined ;
You can’t perform that action at this time.
0 commit comments