19 breaking releases

0.20.0 Mar 10, 2026
0.19.0 Dec 8, 2025
0.18.0 Sep 29, 2023
0.17.0 Nov 25, 2022
0.3.0 Jul 24, 2019

#282 in GUI

Download history 7935/week @ 2026-01-27 10746/week @ 2026-02-03 10626/week @ 2026-02-10 12025/week @ 2026-02-17 11091/week @ 2026-02-24 14491/week @ 2026-03-03 12396/week @ 2026-03-10 12277/week @ 2026-03-17 11739/week @ 2026-03-24 7308/week @ 2026-03-31 7369/week @ 2026-04-07 7635/week @ 2026-04-14 8591/week @ 2026-04-21 6215/week @ 2026-04-28 7008/week @ 2026-05-05 8299/week @ 2026-05-12

30,851 downloads per month
Used in 33 crates (29 directly)

MIT/Apache

660KB
15K SLoC

Provides routing faculties using the browser history API to build Single Page Applications (SPAs) using Yew web framework.

Usage

use yew::functional::*;
use yew::prelude::*;
use yew_router::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Routable)]
enum Route {
    #[at("/")]
    Home,
    #[at("/secure")]
    Secure,
    #[not_found]
    #[at("/404")]
    NotFound,
}

#[component(Secure)]
fn secure() -> Html {
    let navigator = use_navigator().unwrap();

    let onclick_callback = Callback::from(move |_| navigator.push(&Route::Home));
    html! {
        <div>
            <h1>{ "Secure" }</h1>
            <button onclick={onclick_callback}>{ "Go Home" }</button>
        </div>
    }
}

#[component(Main)]
fn app() -> Html {
    html! {
        <BrowserRouter>
            <Switch<Route> render={switch} />
        </BrowserRouter>
    }
}

fn switch(routes: Route) -> Html {
    match routes {
        Route::Home => html! { <h1>{ "Home" }</h1> },
        Route::Secure => html! {
            <Secure />
        },
        Route::NotFound => html! { <h1>{ "404" }</h1> },
    }
}

Internals

The router registers itself as a context provider and makes location information and navigator available via hooks or RouterScopeExt.

State

The Location API has a way to access / store state associated with session history. Please consult location.state() for detailed usage. A module that provides universal session history and location information. A module that provides custom query serialization & deserialization. Prelude module to be imported when working with yew-router.

This module re-exports the frequently used types from the crate.


yew-router

A routing library for the Yew frontend framework.

Read on how to use it on yew.rs

Dependencies

~16–22MB
~336K SLoC