MCPcopy
hub / github.com/sveltejs/kit / resolve_route

Function resolve_route

packages/kit/src/utils/routing.js:241–267  ·  view source on GitHub ↗
(id, params)

Source from the content-addressed store, hash-verified

239 * @returns {string}
240 */
241export function resolve_route(id, params) {
242 const segments = get_route_segments(id);
243 return (
244 '/' +
245 segments
246 .map((segment) =>
247 segment.replace(basic_param_pattern, (_, optional, rest, name) => {
248 const param_value = params[name];
249
250 // This is nested so TS correctly narrows the type
251 if (!param_value) {
252 if (optional) return '';
253 if (rest && param_value !== undefined) return '';
254 throw new Error(`Missing parameter '${name}' in route ${id}`);
255 }
256
257 if (param_value.startsWith('/') || param_value.endsWith('/'))
258 throw new Error(
259 `Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar`
260 );
261 return param_value;
262 })
263 )
264 .filter(Boolean)
265 .join('/')
266 );
267}
268
269/**
270 * @param {import('types').SSRNode} node

Callers 2

routing.spec.jsFile · 0.90
analyseFunction · 0.90

Calls 2

get_route_segmentsFunction · 0.85
filterMethod · 0.65

Tested by

no test coverage detected