You are currently viewing the docs for Dioxus 0.4.3 which is no longer maintained.

Programmatic Navigation

Sometimes we want our application to navigate to another page without having the

Using a Navigator

We can get a navigator with the use_navigator]Navigator]

We can use the Navigator]

  • push will navigate to the target. It works like a regular anchor tag.
  • replace works like push, except that it replaces the current history entry
  • Go back works like the browser's back button.
  • Go forward works like the browser's forward button.
src/navigator.rs
#[component]
fn Home(cx: Scope) -> Element {
    let nav = use_navigator(cx);

    // push
    nav.push(Route::PageNotFound { route: vec![] });

    // replace
    nav.replace(Route::Home {});

    // go back
    nav.go_back();

    // go forward
    nav.go_forward();

    render! {
        h1 { "Welcome to the Dioxus Blog!" }
    }
}

You might have noticed that, like Link]Navigator]push andreplace functions take a NavigationTarget]Internal]External]

External Navigation Targets

Unlike a Link]Navigator]

This means, that under certain conditions, navigation to external targets can