Reference

Link

Client-side navigation link; its label or its block is the link text.

Link(_ label: String, to: Path, active: Enum) { … }

Before 5.0

Example

wf

Stack(gap: .sm) { Link("Start the guide", to: "/learn") Link("Every component", to: "/reference", active: .prefix) Link(to: "/recipes") { Icon("book") Text("Recipes for common screens") } Link("The source on GitHub", to: "https://github.com/webfluent/webfluent", target: "_blank") }

Active on every route beneath it

wf

Link("Reference", to: "/reference").prefix

To a filtered view: active only with its query

wf

Link("Open", to: "/reference?show=open")

Props

Props of Link
PropTypeUnsetMeaning

label

String (positional)

none

The link's words; a block written after it may be its content instead

to:

Path

none

The route or address it goes to, navigated in place; while it matches the current route the link carries .active and aria-current="page"

active:

one of its cases

exact match

How it decides it is the current page: unset, the route must equal to; .prefix also matches routes beneath it. Written as a flag, .prefix, or by name, active: .prefix.

  • .prefix: Also current on every route beneath to: /docs for /docs/forms

Attribute families: global, aria, data, anchor. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.prefix

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events Link answers
EventSendsMeaning
on clickDOMThe element was clicked or activated

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Renders with the class wf-link, stable across releases, so a stylesheet may target it.