Update more examples, add css for more examples

This commit is contained in:
Jonathan Kelley committed 2024-02-14 13:48:58 -08:00
1 parent 60b78668ac
commit cfc119cce2
19 files changed
+228 -101

No files matched your search

+21 -10
View File
@@ -1,20 +1,32 @@
#![allow(non_snake_case)]
//! A simple example of a router with a few routes and a nav bar.
use dioxus::prelude::*;
fn main() {
// Launch the router, using our `Route` component as the generic type
// This will automatically boot the app to "/" unless otherwise specified
launch(|| rsx! { Router::<Route> {} });
}
/// By default, the Routable derive will use the name of the variant as the route
/// You can also specify a specific component by adding the Component name to the `#[route]` attribute
#[rustfmt::skip]
#[derive(Routable, Clone, PartialEq)]
enum Route {
// Wrap the app in a Nav layout
#[layout(Nav)]
#[route("/")]
Homepage {},
#[route("/")]
Homepage {},
#[route("/blog/:id")]
Blog { id: String },
#[route("/blog/:id")]
Blog { id: String },
}
#[component]
fn Homepage() -> Element {
rsx! { h1 { "Welcome home" } }
rsx! {
h1 { "Welcome home" }
}
}
#[component]
@@ -25,6 +37,9 @@ fn Blog(id: String) -> Element {
}
}
/// A simple nav bar that links to the homepage and blog pages
///
/// The `Route` enum gives up typesafe routes, allowing us to rename routes and serialize them automatically
#[component]
fn Nav() -> Element {
rsx! {
@@ -52,7 +67,3 @@ fn Nav() -> Element {
div { Outlet::<Route> {} }
}
}
fn main() {
launch_desktop(|| rsx! { Router::<Route> {} });
}