File tree Expand file tree Collapse file tree 5 files changed +91
-0
lines changed
test/e2e/app-dir/conflicting-search-and-route-params Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { NextRequest } from 'next/server'
2
+
3
+ export async function GET (
4
+ request : NextRequest ,
5
+ { params } : { params : Promise < { id : string } > }
6
+ ) {
7
+ const { id : routeId } = await params
8
+ const searchId = request . nextUrl . searchParams . get ( 'id' )
9
+
10
+ return Response . json ( {
11
+ routeParam : routeId ,
12
+ searchParam : searchId ,
13
+ } )
14
+ }
Original file line number Diff line number Diff line change
1
+ import { ReactNode } from 'react'
2
+
3
+ export default function Root ( { children } : { children : ReactNode } ) {
4
+ return (
5
+ < html >
6
+ < body > { children } </ body >
7
+ </ html >
8
+ )
9
+ }
Original file line number Diff line number Diff line change
1
+ import { Suspense } from 'react'
2
+
3
+ async function SearchAndRouteParams ( {
4
+ searchParams,
5
+ params,
6
+ } : {
7
+ searchParams : Promise < { id ?: string } >
8
+ params : Promise < { id : string } >
9
+ } ) {
10
+ const { id : searchId } = await searchParams
11
+ const { id : routeId } = await params
12
+
13
+ return (
14
+ < div >
15
+ < h1 > Search and Route Parameters</ h1 >
16
+ < p id = "route-param" > Route param id: { routeId } </ p >
17
+ < p id = "search-param" > Search param id: { searchId || 'not provided' } </ p >
18
+ </ div >
19
+ )
20
+ }
21
+
22
+ export default function Page ( {
23
+ searchParams,
24
+ params,
25
+ } : {
26
+ searchParams : Promise < { id ?: string } >
27
+ params : Promise < { id : string } >
28
+ } ) {
29
+ return (
30
+ < Suspense fallback = { < div > Loading...</ div > } >
31
+ < SearchAndRouteParams searchParams = { searchParams } params = { params } />
32
+ </ Suspense >
33
+ )
34
+ }
Original file line number Diff line number Diff line change
1
+ import { nextTestSetup } from 'e2e-utils'
2
+
3
+ describe ( 'conflicting-search-and-route-params' , ( ) => {
4
+ const { next } = nextTestSetup ( {
5
+ files : __dirname ,
6
+ } )
7
+
8
+ it ( 'should handle conflicting search and route params on page' , async ( ) => {
9
+ const browser = await next . browser ( '/render/123?id=456' )
10
+
11
+ const routeParamText = await browser . elementByCss ( '#route-param' ) . text ( )
12
+ expect ( routeParamText ) . toContain ( 'Route param id: 123' )
13
+
14
+ const searchParamText = await browser . elementByCss ( '#search-param' ) . text ( )
15
+ expect ( searchParamText ) . toContain ( 'Search param id: 456' )
16
+ } )
17
+
18
+ it ( 'should handle conflicting search and route params on API route' , async ( ) => {
19
+ // Test with route param "789" and search param "abc"
20
+ const response = await next . fetch ( '/api/789?id=abc' )
21
+ const data = await response . json ( )
22
+
23
+ expect ( data ) . toEqual ( {
24
+ routeParam : '789' ,
25
+ searchParam : 'abc' ,
26
+ } )
27
+ } )
28
+ } )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @type {import('next').NextConfig }
3
+ */
4
+ const nextConfig = { }
5
+
6
+ module . exports = nextConfig
You can’t perform that action at this time.
0 commit comments