silverwolf-x/project / packages /next /src /server /lib /router-utils /build-prefetch-segment-data-route.ts
silverwolf-x's picture
download
raw
1.08 kB
import path from '../../../shared/lib/isomorphic/path'
import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path'
import { getNamedRouteRegex } from '../../../shared/lib/router/utils/route-regex'
import {
RSC_SEGMENT_SUFFIX,
RSC_SEGMENTS_DIR_SUFFIX,
} from '../../../lib/constants'
export const SEGMENT_PATH_KEY = 'nextSegmentPath'
export type PrefetchSegmentDataRoute = {
source: string
destination: string
routeKeys: { [key: string]: string }
}
export function buildPrefetchSegmentDataRoute(
page: string,
segmentPath: string
): PrefetchSegmentDataRoute {
const pagePath = normalizePagePath(page)
const destination = path.posix.join(
`${pagePath}${RSC_SEGMENTS_DIR_SUFFIX}`,
`${segmentPath}${RSC_SEGMENT_SUFFIX}`
)
const { namedRegex, routeKeys } = getNamedRouteRegex(destination, {
prefixRouteKeys: true,
includePrefix: true,
includeSuffix: true,
excludeOptionalTrailingSlash: true,
backreferenceDuplicateKeys: true,
})
return {
destination,
source: namedRegex,
routeKeys,
}
}

Xet Storage Details

Size:
1.08 kB
·
Xet hash:
220d3c0b8b7f9bcdb381c58274018ab829204cb051186f2aaf2225adcbbe27d4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.