History Providers

In order to provide the ability to traverse the navigation history, the router uses HistoryProviders. Those implement the actual back-and-forth functionality.

The router provides five HistoryProviders, but you can also create your own. The five default implementations are:

  • The MemoryHistory is a custom implementation that works in memory.
  • The WebHistory integrates with the browsers URL.
  • The WebHashHistory also integrates with the browser, but uses the fragment part of the URL.

By default the router uses the MemoryHistory. It might be changed to use WebHistory when the web feature is active, but that is not guaranteed.

You can override the default history:


#![allow(unused)]
fn main() {
// Hidden lines (like this one) make the documentation tests work.
extern crate dioxus;
use dioxus::prelude::*;
extern crate dioxus_router;
use dioxus_router::{prelude::*, history::WebHashHistory};

fn App(cx: Scope) -> Element {
    use_router(
        cx,
        &|| RouterConfiguration {
            history: Box::new(WebHashHistory::new(true)),
            ..Default::default()
        },
        &|| Segment::empty()
    );

    render! {
        Outlet { }
    }
}
}