The <page-link> component renders a standard HTML anchor (<a>) tag wrapper that intercepts click events, updates browser history, and highlights itself with an active attribute when matching the current location.

html
<page-link path="/dashboard" title="Admin Panel">Go to Dashboard</page-link>

Attributes

AttributeTypeDefaultDescription
pathstringCurrent PathThe destination pathname (e.g. /home or query-relative parameters).
searchstringundefinedAppends or updates search parameters (e.g. tab=settings).
keep-current-searchbooleanfalseRetains existing URL search parameters when navigating to a new path.
exactbooleantrueWhen true, links are marked active only on an exact pathname match.
titlestringundefinedThe document title to set upon successful navigation.
payloadobject{}History state payload. In HTML, provide a JSON-serialized object string.

Relative Path Resolution

To make page layout structures reusable, <page-link> automatically resolves shorthand prefixes:


Active State Styling

When the browser location matches the link's target, the component gains a native active attribute:

html
<!-- Rendered active HTML element -->
<page-link path="/todos" active>Todos</page-link>

You can target this state in CSS using standard attributes or CSS shadow parts:

css
/* Style the outer custom component element */
page-link[active] {
    font-weight: 700;
}

/* Style the inner anchor tag using shadow parts */
page-link::part(anchor) {
    color: var(--foreground);
    text-decoration: none;
    transition: border-color 0.2s;
}

page-link[active]::part(anchor) {
    border-bottom: 2px solid var(--primary);
    color: var(--primary);
}

Passing Payloads

Use payload to pass history state data to the next page.

In plain HTML, attributes are strings, so payload must be a valid JSON-serialized object:

html
<page-link path="/dashboard" payload='{"role": "admin", "userId": 42}'>
    Enter Panel
</page-link>

When rendering <page-link> through Markup, pass the value as an object property:

javascript
import { html } from '@beforesemicolon/web-component'

const user = { role: 'admin', userId: 42 }

html` <page-link path="/dashboard" payload="${user}"> Enter Panel </page-link> `

The payload is available on the destination route through getPageData(), onPage(), onPageChange(), or <page-data key="...">.

edit this doc