2022-01-05 22:30:12 +00:00
|
|
|
#![allow(non_snake_case)]
|
2021-11-03 04:35:56 +00:00
|
|
|
|
2022-01-05 22:30:12 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus::router::{Link, Route, Router};
|
2022-01-11 17:27:02 +00:00
|
|
|
use serde::Deserialize;
|
2021-11-03 04:35:56 +00:00
|
|
|
|
2022-01-05 22:30:12 +00:00
|
|
|
fn main() {
|
|
|
|
dioxus::desktop::launch(app);
|
2021-11-03 04:35:56 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 23:35:38 +00:00
|
|
|
fn app(cx: Scope) -> Element {
|
2021-11-03 04:35:56 +00:00
|
|
|
cx.render(rsx! {
|
2022-01-05 22:30:12 +00:00
|
|
|
Router {
|
|
|
|
ul {
|
|
|
|
Link { to: "/", li { "Go home!" } }
|
|
|
|
Link { to: "users", li { "List all users" } }
|
|
|
|
Link { to: "blog", li { "Blog posts" } }
|
|
|
|
}
|
|
|
|
Route { to: "/", "Home" }
|
|
|
|
Route { to: "users",
|
|
|
|
Route { to: "/", "User list" }
|
2022-01-25 00:52:12 +00:00
|
|
|
Route { to: ":name", User {} }
|
2022-01-05 22:30:12 +00:00
|
|
|
}
|
|
|
|
Route { to: "blog"
|
|
|
|
Route { to: "/", "Blog list" }
|
|
|
|
Route { to: ":post", BlogPost {} }
|
|
|
|
}
|
|
|
|
Route { to: "", "Err 404 Route Not Found" }
|
2022-01-02 07:15:04 +00:00
|
|
|
}
|
2021-11-03 04:35:56 +00:00
|
|
|
})
|
2022-01-02 23:35:38 +00:00
|
|
|
}
|
2021-11-03 04:35:56 +00:00
|
|
|
|
2022-01-05 22:30:12 +00:00
|
|
|
fn BlogPost(cx: Scope) -> Element {
|
2022-01-11 17:27:02 +00:00
|
|
|
let post = dioxus::router::use_route(&cx).last_segment();
|
2022-01-05 22:30:12 +00:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "Reading blog post: {post}" }
|
|
|
|
p { "example blog post" }
|
2021-11-03 04:35:56 +00:00
|
|
|
}
|
2022-01-05 22:30:12 +00:00
|
|
|
})
|
2021-11-03 04:35:56 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 17:27:02 +00:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct Query {
|
|
|
|
bold: bool,
|
|
|
|
}
|
|
|
|
|
2022-01-05 22:30:12 +00:00
|
|
|
fn User(cx: Scope) -> Element {
|
2022-01-11 17:27:02 +00:00
|
|
|
let post = dioxus::router::use_route(&cx).last_segment();
|
2022-01-25 00:52:12 +00:00
|
|
|
let query = dioxus::router::use_route(&cx)
|
|
|
|
.query::<Query>()
|
|
|
|
.unwrap_or(Query { bold: false });
|
2022-01-05 22:30:12 +00:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "Reading blog post: {post}" }
|
|
|
|
p { "example blog post" }
|
2022-01-25 00:54:27 +00:00
|
|
|
|
2022-01-25 00:52:12 +00:00
|
|
|
if query.bold {
|
|
|
|
rsx!{ b { "bold" } }
|
|
|
|
} else {
|
|
|
|
rsx!{ i { "italic" } }
|
|
|
|
}
|
2022-01-05 22:30:12 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|