react-server675fbba4
react-servercommit09d92970763a

feat: router matchers (#404)

The file-router's underlying match() primitive has long supported named parameter matchers via [param=alias] syntax, but the file-router itself never exposed a way for a dynamic page to actually register its own matcher predicates. This branch closes that gap: a page (or middleware or API route) can now export const matchers = descriptor.createMatchers({ alias: (value) => … }) and the runtime applies those predicates during routing — before any page code loads. This lets sibling routes divide the same parameter slot by shape, for example pairing /product/[sku=uppercase] with a bare /product/[sku] fallback so that rejected SKUs fall through instead of 404ing. Matchers are a strictly routing-layer concern and complement the existing validate export, which only runs after a route has already been selected.

Along the way buildHref turned out to have its own latent bug: its regex used \w+ inside the bracket, so it silently skipped both [name=alias] and every optional form ([[name]], [[...name]]), leaving the raw bracket literal in the emitted URL. The replacement uses an explicit four-alternative regex with the alias suffix as an optional trailing group per form, strips the alias (it's a routing-time concern, not a URL concern), and collapses any // introduced by empty optional substitutions. Documentation in both English and Japanese, the typed-file-router example, and integration tests covering both required and catch-all matchers with their fall-through behavior are included so the whole story is reachable from the nav of the running example.

Author
Viktor Lázár <lazarv1982@gmail.com>
Date
Commit
09d92970763aeb82c82672ce42deebca123a6776
12 files changed+765 -48