dioxus/examples/link.rs

61 lines
1.2 KiB
Rust
Raw Normal View History

2022-01-18 01:19:12 +00:00
use dioxus::prelude::*;
2022-12-16 10:55:20 +00:00
use dioxus_router::prelude::*;
2022-01-18 01:19:12 +00:00
fn main() {
launch(App);
2022-01-18 01:19:12 +00:00
}
#[component]
fn App() -> Element {
2024-01-14 05:12:21 +00:00
rsx! (
2022-01-18 01:20:36 +00:00
div {
2024-01-16 15:40:17 +00:00
p { a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" } }
2022-01-18 01:19:12 +00:00
p {
a {
href: "http://dioxuslabs.com/",
2022-01-18 06:52:14 +00:00
prevent_default: "onclick",
onclick: |_| println!("Hello Dioxus"),
2024-01-16 15:40:17 +00:00
"Custom event link - links inside of your app"
2022-03-05 20:25:09 +00:00
}
}
}
2024-01-16 15:40:17 +00:00
div { Router::<Route> {} }
2024-01-14 05:12:21 +00:00
)
2022-01-18 01:19:12 +00:00
}
2022-12-16 10:55:20 +00:00
2023-06-02 17:33:47 +00:00
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(Header)]
#[route("/")]
Home {},
#[route("/settings")]
Settings {},
}
#[component]
fn Header() -> Element {
2023-06-02 17:33:47 +00:00
render! {
h1 { "Your app here" }
ul {
2024-01-16 15:40:17 +00:00
li {
Link { to: Route::Home {}, "home" }
}
li {
Link { to: Route::Settings {}, "settings" }
}
2023-06-02 17:33:47 +00:00
}
2023-07-26 01:14:48 +00:00
Outlet::<Route> {}
2023-06-02 17:33:47 +00:00
}
}
#[component]
fn Home() -> Element {
2024-01-16 15:40:17 +00:00
render!( h1 { "Home" } )
2022-12-16 10:55:20 +00:00
}
#[component]
fn Settings() -> Element {
2024-01-16 15:40:17 +00:00
render!( h1 { "Settings" } )
2022-12-16 10:55:20 +00:00
}