File tree Expand file tree Collapse file tree 5 files changed +61
-1
lines changed
test/e2e/error-handler-not-found-req-url Expand file tree Collapse file tree 5 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -2649,7 +2649,13 @@ export default abstract class Server<
2649
2649
initPathname = normalizer . normalize ( initPathname )
2650
2650
}
2651
2651
}
2652
- request . url = `${ initPathname } ${ parsedInitUrl . search || '' } `
2652
+
2653
+ // On minimal mode, the request url of dynamic route can be a
2654
+ // literal dynamic route ('/[slug]') instead of actual URL, so overwriting to initPathname
2655
+ // will transform back the resolved url to the dynamic route pathname.
2656
+ if ( ! ( this . minimalMode && isErrorPathname ) ) {
2657
+ request . url = `${ initPathname } ${ parsedInitUrl . search || '' } `
2658
+ }
2653
2659
2654
2660
// propagate the request context for dev
2655
2661
setRequestMeta ( request , getRequestMeta ( req ) )
Original file line number Diff line number Diff line change
1
+ import { nextTestSetup } from 'e2e-utils'
2
+
3
+ describe ( 'error-handler-not-found-req-url' , ( ) => {
4
+ const { next } = nextTestSetup ( {
5
+ files : __dirname ,
6
+ } )
7
+
8
+ it ( 'should log the correct request url and asPath for not found _error page' , async ( ) => {
9
+ const browser = await next . browser ( '/3' )
10
+ const p = await browser . elementByCss ( 'p' )
11
+ expect ( await p . text ( ) ) . toBe ( 'reqUrl: /3, asPath: /3' )
12
+ } )
13
+ } )
Original file line number Diff line number Diff line change
1
+ export default function Page ( ) {
2
+ return < p > hello world</ p >
3
+ }
4
+
5
+ export async function getStaticProps ( ) {
6
+ return {
7
+ notFound : true ,
8
+ }
9
+ }
10
+
11
+ export async function getStaticPaths ( ) {
12
+ return {
13
+ paths : [ ] ,
14
+ fallback : 'blocking' ,
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ import type { NextPageContext } from 'next'
2
+
3
+ Error . getInitialProps = ( ctx : NextPageContext ) => {
4
+ return {
5
+ reqUrl : ctx . req ?. url ,
6
+ asPath : ctx . asPath ,
7
+ }
8
+ }
9
+
10
+ export default function Error ( {
11
+ reqUrl,
12
+ asPath,
13
+ } : {
14
+ reqUrl ?: string
15
+ asPath ?: string
16
+ } ) {
17
+ return (
18
+ < p >
19
+ reqUrl: { reqUrl } , asPath: { asPath }
20
+ </ p >
21
+ )
22
+ }
Original file line number Diff line number Diff line change
1
+ export default function Page ( ) {
2
+ return < p > hello world</ p >
3
+ }
You can’t perform that action at this time.
0 commit comments