dioxus/packages/router/examples/simple.rs

42 lines
1,021 B
Rust
Raw Normal View History

2021-11-19 05:49:04 +00:00
use dioxus_core::prelude::*;
use dioxus_core_macro::*;
use dioxus_html as dioxus_elements;
use dioxus_router::*;
2021-12-29 04:20:01 +00:00
use serde::{Deserialize, Serialize};
2021-11-19 05:49:04 +00:00
fn main() {
console_error_panic_hook::set_once();
2021-11-22 20:22:42 +00:00
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
dioxus_web::launch(APP);
2021-11-19 05:49:04 +00:00
}
static APP: Component<()> = |cx| {
2021-12-29 04:20:01 +00:00
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
2021-11-22 20:22:42 +00:00
enum Route {
Home,
About,
NotFound,
2021-11-19 05:49:04 +00:00
}
2021-12-29 04:20:01 +00:00
impl Default for Route {
fn default() -> Self {
Route::Home
}
}
2021-11-19 05:49:04 +00:00
2021-12-29 04:20:01 +00:00
let route = use_router(&cx, |c| {});
2021-11-22 20:22:42 +00:00
cx.render(rsx! {
div {
{match route {
Route::Home => rsx!(h1 { "Home" }),
Route::About => rsx!(h1 { "About" }),
Route::NotFound => rsx!(h1 { "NotFound" }),
}}
nav {
2021-12-29 04:20:01 +00:00
Link { to: Route::Home, href: "/" }
Link { to: Route::About, href: "/about" }
2021-11-22 20:22:42 +00:00
}
2021-11-19 05:49:04 +00:00
}
2021-11-22 20:22:42 +00:00
})
};