Skip to content

Function: getRequiredPatternParamNames()

API / @xmachines/play-url / index / getRequiredPatternParamNames

function getRequiredPatternParamNames(pattern): string[];

Defined in: packages/play-url/src/framework-params.ts:52

The names of every param the pattern REQUIRES, so an optional one is left out.

A param is optional when its own modifier is ? or *, and when EVERY group above it carries one of the two. ? alone was the test before, and it read /files/:path* and /books{/:id}? as required patterns: a path that fills neither then counted as a gap, the pick was discarded, and a correct parse from Vue Router or SolidJS Router went with it. That is the same class of defect as the all-optional bug of !133, for the modifiers that the fix did not cover.

An optional segment that did not match has no value, and a framework reports none. That is a complete answer and not a partial one, so a MIXED pattern such as /profile/:userId/:tab? keeps the parse of the framework when only :tab is absent.

A pattern whose params are ALL optional reports nothing at all, which reads the same as “the framework matched another route”, so pickOwnParams falls back for it. resolveFrameworkParams settles that case from the PATH instead.

Parameters

ParameterTypeDescription
patternstringA route pattern, for example /profile/:userId/:tab?.

Returns

string[]

The required names, in the order that the pattern declares them. A fresh array, because parsePattern caches the parse that it reads.