freya_router::hooks

Function use_route

Source
pub fn use_route<R: Routable + Clone>() -> R
Expand description

A hook that provides access to information about the current routing location.

The Routable macro will define a version of this hook with an explicit type.

§Panic

  • When the calling component is not nested within a Router component.

§Example


#[derive(Clone, Routable)]
enum Route {
    #[route("/")]
    Index {},
}

#[component]
fn App() -> Element {
    rsx!(
        label { "App" }
        Router::<Route> {}
    )
}

#[component]
fn Index() -> Element {
    let path: Route = use_route();
    rsx!(
        label { "Current Path: {path}" }
    )
}