MCPcopy
hub / github.com/TanStack/router / encodeParam

Function encodeParam

packages/router-core/src/path.ts:241–262  ·  view source on GitHub ↗
(
  key: string,
  params: InterpolatePathOptions['params'],
  decoder: InterpolatePathOptions['decoder'],
)

Source from the content-addressed store, hash-verified

239}
240
241function encodeParam(
242 key: string,
243 params: InterpolatePathOptions['params'],
244 decoder: InterpolatePathOptions['decoder'],
245): any {
246 const value = params[key]
247 if (typeof value !== 'string') return value
248
249 if (key === '_splat') {
250 // Early return if value only contains URL-safe characters (performance optimization)
251 if (/^[a-zA-Z0-9\-._~!/]*$/.test(value)) return value
252 // the splat/catch-all routes shouldn't have the '/' encoded out
253 // Use encodeURIComponent for each segment to properly encode spaces,
254 // plus signs, and other special characters that encodeURI leaves unencoded
255 return value
256 .split('/')
257 .map((segment) => encodePathParam(segment, decoder))
258 .join('/')
259 } else {
260 return encodePathParam(value, decoder)
261 }
262}
263
264/**
265 * Interpolate params and wildcards into a route path template.

Callers 1

interpolatePathFunction · 0.85

Calls 1

encodePathParamFunction · 0.85

Tested by

no test coverage detected