yew-nav-link
Enterprise-grade navigation library for Yew — automatic active state detection and a complete component system.
Table of Contents
- Overview
- Installation
- Requirements
- Quick Start
- Components
- CSS Integration
- Architecture
- Examples
- API Reference
- Migration Guides
- Coverage
- Contributing
- License
Overview
yew-nav-link is a comprehensive navigation library for the Yew web framework. It provides:
| Feature | Description |
|---|---|
| NavLink | Drop-in replacement for Yew Router's <Link> with automatic active class detection |
| Component System | 15+ ready-to-use UI components (tabs, dropdowns, pagination, badges, icons) |
| Hooks | Reactive hooks for route state, active checking, breadcrumbs, and programmatic navigation |
| Utilities | Path manipulation, URL encoding, keyboard navigation, and query string handling |
| Customization | Custom CSS classes, programmatic navigation, and extensible breadcrumb providers |
The core NavLink component eliminates manual active state tracking. It compares the current route against the target on every render and applies the active CSS class automatically — zero configuration required.
Installation
[]
= "0.9"
Requirements
| Dependency | Version |
|---|---|
| Rust | 1.85+ |
| Edition | 2024 |
| Yew | 0.23+ |
| yew-router | 0.20+ |
Quick Start
Component Syntax
use *;
use NavLink;
use *;
When the user visits /about, the second link automatically receives class="nav-link active".
Function Syntax
use *;
use ;
use *;
Partial Matching
Keep parent links highlighted on nested routes:
html!
Partial matching is segment-aware: /docs matches /docs/api but not /documentation.
Custom CSS Classes
Customize the default nav-link and active classes:
html!
Programmatic Navigation
use use_navigation;
Custom Breadcrumb Providers
use ;
;
Components
Core Navigation
| Component | Purpose |
|---|---|
NavLink<R> |
Navigation link with automatic active state |
[NavList] |
Accessible navigation list container (<ul> with ARIA) |
[NavItem] |
Navigation list item (<li>) |
[NavDivider] |
Visual separator between navigation groups |
UI Components
| Component | Purpose |
|---|---|
[NavBadge] |
Badge/counter for navigation items |
[NavHeader] |
Section header for navigation groups |
[NavText] |
Plain text element within navigation |
[NavIcon] |
Icon with configurable size |
[NavLinkWithIcon] |
Link with integrated icon |
[NavDropdown] |
Dropdown menu with items and dividers |
[NavTabs] |
Tabbed navigation container |
[NavTab] |
Individual tab with active state |
[NavTabPanel] |
Content panel for tabs |
[Pagination] |
Page navigation controls |
[PageItem] |
Individual page indicator |
[PageLink] |
Clickable page link |
Hooks
| Hook | Returns | Description |
|---|---|---|
use_route_info() |
RouteInfo<R> |
Current route, path, and query parameters |
use_is_active(route) |
bool |
Whether the given route is currently active |
use_is_exact_active(route) |
bool |
Whether the route matches exactly |
use_is_partial_active(route) |
bool |
Whether the route is a prefix of the current path |
use_breadcrumbs() |
Vec<BreadcrumbItem> |
Auto-generated breadcrumb trail from current route |
use_navigation<R>() |
Navigation<R> |
Programmatic navigation (push, replace, go back/forward) |
use_route_params() |
RouteParams |
URL route parameters (/users/:id) |
use_query_params() |
QueryParams |
URL query string parameters |
Utilities
| Function | Description |
|---|---|
is_absolute(path) |
Check if a path starts with / |
join_paths(a, b) |
Join two path segments safely |
normalize_path(path) |
Remove duplicate slashes and trailing slashes |
urlencoding_encode(s) |
Percent-encode a string for URLs |
urlencoding_decode(s) |
Decode a percent-encoded string |
handle_arrow_key(config, key) |
Keyboard navigation handler |
handle_home_end(config, key) |
Home/End key handler for navigation |
CSS Integration
Bootstrap 5
Works out of the box — nav-link and active are native Bootstrap classes.
to={Route::Home}>{ "Home" }>
<!-- Renders: <a class="nav-link active" href="/">Home</a> -->
Tailwind CSS
Define your own nav-link and active styles:
}
}
Architecture
yew-nav-link
├── active_link # Core NavLink component + Match enum
├── nav # Primitives: NavList, NavItem, NavDivider
├── components # UI: Badge, Dropdown, Icon, Tabs, Pagination
├── hooks # Reactive and programmatic route/navigation helpers
├── utils # Path, URL, keyboard navigation utilities
├── attrs # Type-safe attribute builders
└── errors # NavError, NavResult types
See the source code and inline documentation for detailed design documentation.
Examples
Run the comprehensive interactive demo:
Open http://127.0.0.1:8080 for live demos, code snippets, and architecture diagrams for every component.
API Reference
NavLink<R>
| Prop | Type | Default | Description |
|---|---|---|---|
to |
R: Routable |
required | Target route |
children |
Children |
required | Link content |
partial |
bool |
false |
Enable prefix matching |
class |
&str |
"nav-link" |
Custom CSS class (replaces default) |
active_class |
&str |
"active" |
Custom active state class |
Match
| Variant | Behavior |
|---|---|
Exact |
Active only on exact path match |
Partial |
Active when current path starts with target (segment-wise) |
nav_link<R> Function
BreadcrumbItem
Migration Guides
| From | To | Guide |
|---|---|---|
| 0.5.x | 0.6.x | See CHANGELOG.md |
| 0.6.x | 0.7.x | See CHANGELOG.md |
Target: 95%+ coverage, tracked via Codecov.
Sunburst
The inner-most circle is the entire project, moving outward are folders then individual files. Size and color represent statement count and coverage.
Grid
Each block represents a single file. Size and color represent statement count and coverage.
Icicle
Top section is the entire project, proceeding through folders to individual files.
Contributing
See CONTRIBUTING.md for the contribution workflow and code standards.
License
Licensed under the MIT License.