mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-25 21:50:20 +00:00
20d146d9bd
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
68 lines
1.8 KiB
Rust
68 lines
1.8 KiB
Rust
//! 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
|
|
dioxus::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("/blog/:id")]
|
|
Blog { id: String },
|
|
}
|
|
|
|
#[component]
|
|
fn Homepage() -> Element {
|
|
rsx! { h1 { "Welcome home" } }
|
|
}
|
|
|
|
#[component]
|
|
fn Blog(id: String) -> Element {
|
|
rsx! {
|
|
h1 { "How to make: " }
|
|
p { "{id}" }
|
|
}
|
|
}
|
|
|
|
/// 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! {
|
|
nav {
|
|
li {
|
|
Link { to: Route::Homepage {}, "Go home" }
|
|
}
|
|
li {
|
|
Link {
|
|
to: Route::Blog {
|
|
id: "Brownies".to_string(),
|
|
},
|
|
onclick: move |_| { println!("Clicked on Brownies") },
|
|
"Learn Brownies"
|
|
}
|
|
}
|
|
li {
|
|
Link {
|
|
to: Route::Blog {
|
|
id: "Cookies".to_string(),
|
|
},
|
|
"Learn Cookies"
|
|
}
|
|
}
|
|
}
|
|
div { Outlet::<Route> {} }
|
|
}
|
|
}
|