dioxus/docs/router/examples/routing_update.rs

42 lines
757 B
Rust
Raw Normal View History

2023-06-01 22:31:13 +00:00
#![allow(non_snake_case, unused)]
use dioxus::prelude::*;
use dioxus_router::prelude::*;
// ANCHOR: router
#[derive(Routable, Clone, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/home")]
Home {},
}
#[inline_props]
fn Home(cx: Scope) -> Element {
render! {
p { "Home" }
}
}
#[inline_props]
fn Index(cx: Scope) -> Element {
render! {
p { "Index" }
}
}
fn app(cx: Scope) -> Element {
render! {
Router {
config: || RouterConfig::default().on_update(|state|{
2023-06-02 17:33:47 +00:00
(state.current() == Route::Index {}).then_some(
2023-06-01 22:31:13 +00:00
NavigationTarget::Internal(Route::Home {})
2023-06-02 17:33:47 +00:00
)
2023-06-01 22:31:13 +00:00
})
}
}
}
// ANCHOR_END: router
fn main() {}