forked from DioxusLabs/dioxus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_router.rs
42 lines (36 loc) · 914 Bytes
/
simple_router.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 },
}
#[component]
fn Homepage(cx: Scope) -> Element {
render! { h1 { "Welcome home" } }
}
#[component]
fn Blog(cx: Scope, id: String) -> Element {
render! {
h1 { "How to make: " }
p { "{id}" }
}
}
#[component]
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> {}));
}