Technical reference · current source

Grammar and API notes

Four route forms, explicit bindings, structured diagnostics.

Four forms, one registry

Choose a form for what the route expresses. Ordinary resource URLs can stay ordinary URLs.

Page case

/settings~security

A section within a named page. The registry resolves the page and section together.

Param case

/~profile;42

A symbolic key with positional arguments. The example binds 42 to a query parameter.

Dot case

/~billing.invoice.list

A namespaced symbolic destination. Dot-separated key tokens stay distinct from argument values.

Intent case

/~search;q.routing;page.2

Named values make bindings explicit. Unknown argument behavior is an application choice.

From anchor text to a route record

  1. Parse

    Normalize the input and identify a page, positional, dot, or named-argument instruction.

  2. Validate

    Check registered destinations, required arguments, argument limits and unknown named values.

  3. Resolve

    Bind params, query values and a hash. Pass the result to your framework’s router after your application’s checks.

A route registry is not an authorization policy. Permission metadata does not enforce permissions. Validate access independently, and keep sensitive route mappings private.

Use the core APIs

The parser can throw an AnchorRouteError. The validator and resolver return structured diagnostics. Builders handle escaping; do not concatenate untrusted arguments into route strings.

import { buildIntentAnchor, parseAnchor, validateAnchor, resolveAnchor }
  from '@nextera.one/anchor-routing-core';

const anchor = buildIntentAnchor('search', { q: 'route.registry', page: '2' });
// /~search;q.route%2Eregistry;page.2

const instruction = parseAnchor(anchor);
const check = validateAnchor(instruction, registry);
const result = resolveAnchor(instruction, registry);
// This example registry binds q and page into query values.
// Inspect result.success before handing it to a router.

Reserved dots, tildes and semicolons inside values must be percent-escaped. Serialization preserves named-argument insertion order; it does not promise alphabetic canonical ordering. A resolved path is not automatic interpolation of :params; adapters may need an explicit mapping.

Normalization and errors

The core trims input, can extract the pathname from an absolute URL, removes query and fragment suffixes, and normalizes repeated or trailing slashes. It parses data; it does not fetch the URL.

Use the SDK’s own builders for literal values. Malformed percent escapes, duplicate named arguments, unknown registry entries and missing required arguments produce diagnostics. The current unpublished patch also rejects inherited object-property lookups; do not assume earlier npm artifacts contain that fix.

For targets with namedBind, unknown named arguments default to rejection. The ignore and keep policies change how extra names are treated; they do not grant access. The demo limits positional arguments to eight.

Discovery is a separate draft

Declaration draft version 1 defines /.well-known/anchor-routing.json, its text counterpart, and optional /ar.txt. Core 0.2 added helpers for these declarations.

The current SDK parser is tolerant. A parsed declaration does not establish conformance, endpoint availability or trust.