forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment.ts
More file actions
29 lines (23 loc) · 832 Bytes
/
segment.ts
File metadata and controls
29 lines (23 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { Segment } from '../../server/app-render/types'
export function isGroupSegment(segment: string) {
// Use array[0] for performant purpose
return segment[0] === '(' && segment.endsWith(')')
}
export function isParallelRouteSegment(segment: string) {
return segment.startsWith('@') && segment !== '@children'
}
export function addSearchParamsIfPageSegment(
segment: Segment,
searchParams: Record<string, string | string[] | undefined>
) {
const isPageSegment = segment.includes(PAGE_SEGMENT_KEY)
if (isPageSegment) {
const stringifiedQuery = JSON.stringify(searchParams)
return stringifiedQuery !== '{}'
? PAGE_SEGMENT_KEY + '?' + stringifiedQuery
: PAGE_SEGMENT_KEY
}
return segment
}
export const PAGE_SEGMENT_KEY = '__PAGE__'
export const DEFAULT_SEGMENT_KEY = '__DEFAULT__'