Skip to content

pathForSite

pathForSite(entries, siteRootNodeId?): string | undefined

The published path to use for one site, out of a value’s paths.

A Component can be bound at more than one address — the same card placed under two sections, the same page reachable from two sites — so delivery reports the whole set and never picks, because picking needs a tiebreak only the consumer has. This is that tiebreak, written once:

  • siteRootNodeId named: the entry for that site, or undefined if it is bound at none of yours. That is the correct answer for a multi-site consumer, and it is deliberately not “fall back to somebody else’s site” — a link to the wrong site is worse than no link.
  • siteRootNodeId omitted: the first entry. Right for a single-site consumer (every entry names the same site), and honest about being arbitrary otherwise.
  • No entries, or paths absent because the read did not ask for it: undefined.

A undefined result is a normal state, not an error — the target may simply not be published anywhere yet. Render the label as plain text rather than a dead link.

An entry in a different site from the request’s own carries an absolute url, and that is what this returns for it — a relative path into another site is not a usable link (and under a localeHost site would be a different, wrong page). An entry with no url returns its path. The result is always a valid href; it is a path only when the entry is same-site.

readonly ComponentPathEntry[] | undefined

string

string | undefined