mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 14:10:20 +00:00
Add simpler router
This commit is contained in:
parent
694fc22acb
commit
30f8218251
1 changed files with 42 additions and 0 deletions
42
examples/simple_router.rs
Normal file
42
examples/simple_router.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
#![allow(non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
|
||||
#[derive(Routable, Clone, PartialEq)]
|
||||
enum Route {
|
||||
#[layout(Nav)]
|
||||
#[route("/")]
|
||||
Homepage {},
|
||||
|
||||
#[route("/blog/:id")]
|
||||
Blog { id: String },
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Homepage(cx: Scope) -> Element {
|
||||
render! { h1 { "Welcome home" } }
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Blog(cx: Scope, id: String) -> Element {
|
||||
render! {
|
||||
h1 { "How to make: " }
|
||||
p { "{id}" }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Nav(cx: Scope) -> Element {
|
||||
render! {
|
||||
nav {
|
||||
li { Link { to: Route::Homepage { }, "Go home" } }
|
||||
li { Link { to: Route::Blog { id: "Brownies".to_string() }, "Learn Brownies" } }
|
||||
li { Link { to: Route::Blog { id: "Cookies".to_string() }, "Learn Cookies" } }
|
||||
}
|
||||
div { Outlet::<Route> {} }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(|cx| render!(Router::<Route> {}));
|
||||
}
|
Loading…
Reference in a new issue