yew-nav-link
Navigation link component for Yew with automatic active state detection.
Table of Contents
Overview
yew-nav-link provides a NavLink component that wraps Yew Router's Link with automatic active state management. When the target route matches the current URL, an active CSS class is applied automatically.
Installation
[]
= "0.4"
Requirements
| Dependency | Version |
|---|---|
| yew | 0.22+ |
| yew-router | 0.19+ |
Examples
Full working examples are available in the examples/ directory:
| Example | Description |
|---|---|
| basic | Simple navigation with Home, About, Contact pages |
| bootstrap | Integration with Bootstrap 5 navbar |
| tailwind | Sidebar navigation styled with Tailwind CSS |
| nested-routes | Multi-level navigation with partial matching |
Running Examples
# Install prerequisites (once)
# Run example
Open http://127.0.0.1:8080 in your browser.
Usage
Component Syntax
use *;
use NavLink;
use *;
Function Syntax
For text-only links, use nav_link with explicit Match mode:
use *;
use ;
use *;
Partial Matching
Use partial prop to keep parent links active on nested routes:
use *;
use NavLink;
use *;
CSS Classes
The component applies these classes to the rendered <a> element:
| Class | When Applied |
|---|---|
nav-link |
Always |
active |
Route matches current URL |
Bootstrap Integration
to={Route::Home}>{ "Home" }>
<!-- Renders: <a class="nav-link active" href="/">Home</a> -->
Tailwind CSS
}
}
API Reference
NavLink<R> Component
| Prop | Type | Default | Description |
|---|---|---|---|
to |
R: Routable |
required | Target route |
children |
Children |
required | Link content |
partial |
bool |
false |
Enable prefix matching |
Match Enum
| Variant | Description |
|---|---|
Match::Exact |
Active only on exact path match |
Match::Partial |
Active when current path starts with target |
nav_link<R> Function
Creates a NavLink with text content and specified match mode.
Code coverage is tracked via Codecov. Target: 95%+ coverage.
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice represents the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block represents the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice represents the number of statements and the coverage, respectively.
License
Licensed under the MIT License.