mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
c866ae602b
* Add `#[component]` attribute + system for creating component attributes + other stuff * Delete inlineprops.rs * Update inline_props.rs * Cargo fmt * Fix clippy warnings and paths in props/mods.rs * Include where clause in `#[inline_props]` output * Allow Clippy type complexity in `LinkProps` * Allow the type complexity lint for the entire link.rs file * Remove snake_case -> PascalCase converter, but rather enforce PascalCase Also: - Put the second function inside the main one instead of besides it. - Simplify * Simplify type check lints so they don't return false positives They will not always work, but they won't return any false positives, like for aliases. This is likely going to be replaced by a more polished Clippy-backed linting system. * Fix #583 * Cargo fmt * Add docs for `deserialize()` and remove useless comment * Add `#[component]` to prelude * Merge branch 'master' of https://github.com/tigerros/dioxus * #[inline_props] is no more. Except in the docs folder, but that's going to be removed * Remove docs folder * Remove docs from workspace * Resolve `DeserializerOutput` conversation
111 lines
2.3 KiB
Rust
111 lines
2.3 KiB
Rust
use dioxus::prelude::*;
|
|
use dioxus_router::prelude::*;
|
|
|
|
fn main() {
|
|
#[cfg(target_arch = "wasm32")]
|
|
dioxus_web::launch(App);
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
dioxus_desktop::launch(App);
|
|
}
|
|
|
|
// ANCHOR: router
|
|
#[derive(Routable, Clone)]
|
|
#[rustfmt::skip]
|
|
enum Route {
|
|
#[layout(NavBar)]
|
|
#[route("/")]
|
|
Home {},
|
|
#[nest("/blog")]
|
|
#[layout(Blog)]
|
|
#[route("/")]
|
|
BlogList {},
|
|
#[route("/blog/:name")]
|
|
BlogPost { name: String },
|
|
#[end_layout]
|
|
#[end_nest]
|
|
#[end_layout]
|
|
#[nest("/myblog")]
|
|
#[redirect("/", || Route::BlogList {})]
|
|
#[redirect("/:name", |name: String| Route::BlogPost { name })]
|
|
#[end_nest]
|
|
#[route("/:..route")]
|
|
PageNotFound {
|
|
route: Vec<String>,
|
|
},
|
|
}
|
|
// ANCHOR_END: router
|
|
|
|
#[component]
|
|
fn App(cx: Scope) -> Element {
|
|
render! {
|
|
Router::<Route> {}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn NavBar(cx: Scope) -> Element {
|
|
render! {
|
|
nav {
|
|
ul {
|
|
li { Link { to: Route::Home {}, "Home" } }
|
|
li { Link { to: Route::BlogList {}, "Blog" } }
|
|
}
|
|
}
|
|
Outlet::<Route> {}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Home(cx: Scope) -> Element {
|
|
render! {
|
|
h1 { "Welcome to the Dioxus Blog!" }
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Blog(cx: Scope) -> Element {
|
|
render! {
|
|
h1 { "Blog" }
|
|
Outlet::<Route> {}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn BlogList(cx: Scope) -> Element {
|
|
render! {
|
|
h2 { "Choose a post" }
|
|
ul {
|
|
li {
|
|
Link {
|
|
to: Route::BlogPost { name: "Blog post 1".into() },
|
|
"Read the first blog post"
|
|
}
|
|
}
|
|
li {
|
|
Link {
|
|
to: Route::BlogPost { name: "Blog post 2".into() },
|
|
"Read the second blog post"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn BlogPost(cx: Scope, name: String) -> Element {
|
|
render! {
|
|
h2 { "Blog Post: {name}"}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn PageNotFound(cx: Scope, route: Vec<String>) -> Element {
|
|
render! {
|
|
h1 { "Page not found" }
|
|
p { "We are terribly sorry, but the page you requested doesn't exist." }
|
|
pre {
|
|
color: "red",
|
|
"log:\nattemped to navigate to: {route:?}"
|
|
}
|
|
}
|
|
}
|