Skip to content

normalizeSlotRoute

normalizeSlotRoute(input): string | null

Normalize a path, URL or route pattern into a slot route.

Strips any origin, query string and fragment; collapses duplicate slashes and a trailing slash; keeps route-pattern segments ([id], :id) verbatim; templates identifier-like segments to :id; bounds the result to SLOT_ROUTE_MAX_LENGTH. Returns null for empty or non-string input.

string | null | undefined

string | null

TypeScript
normalizeSlotRoute('https://app.example.com/accounts/4821/billing?tab=x#top');
// → '/accounts/:id/billing'
normalizeSlotRoute('/projects/[projectId]');
// → '/projects/[projectId]'