Back to Overview
CORE CONCEPTSAvailable

Relation

A Relation defines directed edges and transition outcomes following an interactive action.


Definition & Purpose

A Relation defines where a user or system lands after an action occurs. It acts as a directed edge in the UXDL graph, linking an action to a destination screen, state, external URL, or terminal end-point.

Three Destination Forms

Every relation MUST declare exactly one of the three destination forms:

  • 1. 'to' (string) — Target screen ID, with optional target 'state' ID.
  • 2. 'external' (string) — External URL outside the modeled experience (e.g. Stripe checkout URL).
  • 3. 'end: true' (boolean) — Intentional terminal flow screen (e.g. account deleted).

Address Syntax & Examples

Relation addresses append .relations.relation_id to the action address:

YAML
Address format:
screen_id.actions.action_id.relations.relation_id
Real-world domain address examples:
- checkout.actions.retry_payment.relations.success
- sign_in.actions.submit.relations.invalid_password
- billing.actions.cancel.relations.review_modal

Flowchart Edge Representation

In Canvas view, relations render as directed arrows connecting actions to target screens or states, annotated with natural-language 'when' conditions.

Complete Valid Example

Here is an action with three relations demonstrating all three destination forms:

YAML
actions:
submit_order:
name: Finalize Order
relations:
internal_success:
to: order_confirmation
state: confirmed
when: Internal card payment succeeds
external_gateway:
external: "https://checkout.stripe.com/c/pay/123"
when: User selects PayPal / external gateway
terminal_cancel:
end: true
when: Buyer cancels session permanently

What a Relation Does NOT Mean

A UXDL Relation is NOT a database foreign key constraint, NOT a Next.js router.push() call, and NOT an HTTP 302 redirect header. It describes a graph transition outcome.

Connected Primitives & Best Practices

  • Action — Every relation MUST belong strictly to an action.
  • Single destination rule — Declaring multiple destination forms (e.g. both 'to' and 'external') is a structural error.
  • Natural language 'when' — Use concise conditions explaining when the relation branch fires.