[data-reveal]{opacity:1!important;transform:none!important}
Guard
Components

Guard

Shows its blocks, or one empty state in their place when a route says there is nothing to show yet or the record is gone.

Guard renders its children unchanged, unless a route says there is nothing for them: then it draws one EmptyState — the fallback — in their place. A tab of charts about a route that was never called draws "No calls yet" and a link to call it, rather than a page of empty charts. The blocks of a deleted record give way to one "Not found" rather than each failing on its own.

GuardGuard
Connecting to the DMS preview…
ConnectingDMS 0.9.53 options set

The fixed alert dataset is empty, so the fallback replaces the children. The static screenshot shows this same state when the live renderer is unavailable.

Usage

src/pages/routes.ts
import { Guard } from "@antelopejs/interface-dms/base/guard";

static statistics = Guard({
  fetchUrl: "/api/routes/activity?route={{query.route}}", // answers { calls: 0 }
  periodScope: "api",
  realtimeTopic: "requests",
  field: "calls",
  fallback: {
    title: "$api.routes.statistics.idle_title",
    description: "$api.routes.statistics.idle_description",
    icon: "i-ph-moon-stars",
    actions: [{ label: "$api.routes.test", to: "/modules/api/routes?tab=tester" }],
  },
}).child("charts", Grid().child("row", GridRow().child("latency", ChartCard({ /* … */ }))));

Options

Options of the Guard block
OptionTypeDefaultDescription
fallback.titleContentstring–Title of the empty state.
fallback.descriptionContentstring–
fallback.code.content*Contentstring–
fallback.code.languageContent"json" | "javascript" | "typescript" | "html" | "sql" | "shell" | …–
fallback.code.copyContentboolean–
fallback.variantAppearance"no-data" | "no-result" | "no-access" | "error""no-data"Why it is empty; sets the icon and the tone.
fallback.iconAppearancestring–Overrides the variant's icon.
fallback.toneAppearance"neutral" | "primary" | "secondary" | "success" | "warning" | "error" | …–
fallback.sizeAppearance"sm" | "md" | "lg""md"
fallback.hatchedAppearanceboolean–Hatched panel behind it.
fallback.cardAppearancebooleantrueDraws the block on a card; turn it off when it already sits in one.
whenThe fallback replaces the children when…
emptythe value at field (or the whole answer) is absent, null, false, 0, "" or [].
notFoundthe route answers 404.

Recipes

One "Not found" for a detail page

src/pages/route-detail.ts
static body = Guard({ fetchUrl: "/api/routes/{{params.id}}", when: "notFound" })
  .child("overview", KeyValueList({ fetchUrl: "/api/routes/{{params.id}}/summary" }))
  .child("activity", ActivityFeed({ fetchUrl: "/api/routes/{{params.id}}/activity" }));

The guard draws what a block whose source answers 404 draws: "Not found", the 404 body's message as its description, and the same icon. fallback is laid over these defaults (Not found).

Let the route say more

An emptyState object in the answer — or in the 404 body, for notFound — is laid over fallback, for what only the route knows: when the record was last used, or a link carrying its id.

Pitfalls

  • The children show while the route loads, after any failure other than the condition (a 500, a timeout), and whenever the value is set. A realtime event, a new period or a page refresh that sets the value brings them back.
  • Nothing is requested while a {{params.X}} / {{query.X}} token has no value, and the children show.
  • Only what is inside gives way. Keep a toolbar or a table that should stay outside the guard.

Next steps

Empty state

The options of the fallback.

Block fundamentals

How blocks read routes, tokens and 404s.