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::*;
|
|
|
|
|
|
|
|
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));
|
2021-11-19 05:49:04 +00:00
|
|
|
dioxus_web::launch(App, |c| c);
|
|
|
|
}
|
|
|
|
|
2021-12-10 02:19:31 +00:00
|
|
|
static App: Component<()> = |cx, props| {
|
2021-11-22 20:22:42 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
enum Route {
|
|
|
|
Home,
|
|
|
|
About,
|
|
|
|
NotFound,
|
2021-11-19 05:49:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 20:22:42 +00:00
|
|
|
let route = use_router(cx, |s| match s {
|
|
|
|
"/" => Route::Home,
|
|
|
|
"/about" => Route::About,
|
|
|
|
_ => Route::NotFound,
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
{match route {
|
|
|
|
Route::Home => rsx!(h1 { "Home" }),
|
|
|
|
Route::About => rsx!(h1 { "About" }),
|
|
|
|
Route::NotFound => rsx!(h1 { "NotFound" }),
|
|
|
|
}}
|
|
|
|
nav {
|
|
|
|
Link { to: Route::Home, href: |_| "/".to_string() }
|
|
|
|
Link { to: Route::About, href: |_| "/about".to_string() }
|
|
|
|
}
|
2021-11-19 05:49:04 +00:00
|
|
|
}
|
2021-11-22 20:22:42 +00:00
|
|
|
})
|
|
|
|
};
|