DioxusLabs/dioxus · error

`use_route` must be called in a descendant of a Router compo

Error message

`use_route` must be called in a descendant of a Router component

What it means

use_route called use_router_internal() and received None, meaning the component is not a descendant of a Router component. The hook cannot resolve the current route without router context, so it panics immediately.

Source

Thrown at packages/router/src/hooks/use_route.rs:48

/// fn Index() -> Element {
///     let path: Route = use_route();
///     rsx! {
///         h2 { "Current Path" }
///         p { "{path}" }
///     }
/// }
/// #
/// # let mut vdom = VirtualDom::new(App);
/// # vdom.rebuild_in_place();
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><h2>Current Path</h2><p>/</p>")
/// ```
#[doc(alias = "use_url")]
#[must_use]
pub fn use_route<R: Routable + Clone>() -> R {
    match use_router_internal() {
        Some(r) => r.current(),
        None => {
            panic!("`use_route` must be called in a descendant of a Router component")
        }
    }
}

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Call use_route only in components that are descendants of a Router component.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/router/src/hooks/use_route.rs:48 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/5e3c86443ac878f7. Report an issue: GitHub.