dioxus/docs/router/examples/first_route.rs

37 lines
796 B
Rust
Raw Normal View History

2023-06-01 18:13:59 +00:00
// ANCHOR: router
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_router::prelude::*;
/// An enum of all of the possible routes in the app.
#[derive(Routable, Clone)]
enum Route {
// The home page is at the / route
#[route("/")]
// If the name of the component and variant are the same you can omit the component and props name
2023-06-01 22:31:13 +00:00
// If they are different you can specify them like this:
2023-06-01 18:13:59 +00:00
// #[route("/", ComponentName, PropsName)]
Home {},
}
// ANCHOR_END: router
// ANCHOR: app
#[inline_props]
fn App(cx: Scope) -> Element {
render! {
2023-07-26 01:14:48 +00:00
Router::<Route> {}
2023-06-01 18:13:59 +00:00
}
}
// ANCHOR_END: app
// ANCHOR: home
#[inline_props]
fn Home(cx: Scope) -> Element {
render! {
h1 { "Welcome to the Dioxus Blog!" }
}
}
// ANCHOR_END: home
fn main() {}