Link
Accessible link component with external link handling and router integration.
Usage
<w-link href="/about">About Us</w-link>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | "" | Link destination |
external | boolean | false | Opens in new tab with security |
disabled | boolean | false | Disables the link |
variant | string | "default" | Style variant: default, subtle, underline |
Examples
Basic Link
<w-link href="/home">Go Home</w-link>
External Link
<w-link href="https://github.com" external>
View on GitHub
</w-link>
When external is set:
- Opens in new tab (
target="_blank") - Adds
rel="noopener noreferrer"for security - Prevents tabnabbing attacks
Disabled Link
<w-link href="/premium" disabled>
Premium Feature (Coming Soon)
</w-link>
With Navigation
w-link integrates seamlessly with w-nav for site navigation:
<w-nav label="Main navigation">
<w-slot item><w-link href="/home">Home</w-link></w-slot>
<w-slot item><w-link href="/about">About</w-link></w-slot>
<w-slot item><w-link href="https://docs.example.com" external>Docs</w-link></w-slot>
</w-nav>
With Breadcrumb
<w-breadcrumb label="Breadcrumb">
<w-slot item><w-link href="/">Home</w-link></w-slot>
<w-slot sep><span>/</span></w-slot>
<w-slot item><w-link href="/products">Products</w-link></w-slot>
<w-slot sep><span>/</span></w-slot>
<w-slot item><span aria-current="page">Widget</span></w-slot>
</w-breadcrumb>
Styling
/* Base link styles */
w-link {
color: #0066cc;
}
w-link:hover {
text-decoration: underline;
}
/* External link indicator */
w-link[external]::after {
content: " ↗";
font-size: 0.8em;
}
/* Disabled state */
w-link[disabled] {
opacity: 0.5;
cursor: not-allowed;
}
/* Variants */
w-link[variant="subtle"] {
text-decoration: none;
}
w-link[variant="underline"] {
text-decoration: underline;
}
Router Integration
When used with waria.start({ hash: true }), links inside w-nav are automatically converted to hash-based URLs for client-side routing:
<!-- This link -->
<w-link href="/about">About</w-link>
<!-- Becomes (in hash mode) -->
<w-link href="#/about">About</w-link>
Accessibility
- Proper link semantics with
<a>element - External links include security attributes
- Disabled state uses
aria-disabledand prevents navigation - Works with keyboard navigation (Tab, Enter)
- Screen readers announce external links appropriately