add a fixed route to example

This commit is contained in:
Adrian Wannenmacher 2022-12-09 04:11:31 +01:00
parent 780786c520
commit 3d752e31ec
No known key found for this signature in database
GPG key ID: 19D986ECB1E492D5

View file

@ -2,6 +2,7 @@
use dioxus::prelude::*;
use dioxus_router::prelude::*;
use dioxus_router_core::history::MemoryHistory;
fn main() {
dioxus_desktop::launch(App);
@ -11,19 +12,44 @@ fn App(cx: Scope) -> Element {
use_router(
&cx,
&|| RouterConfiguration {
// history: Box::new(MemoryHistory::with_initial_path("/apple").unwrap()),
..Default::default()
},
&|| Segment::content(comp(RootIndex)),
&|| Segment::content(comp(RootIndex)).fixed("apple", comp(Apple)),
);
render! {
h1 { "hi" }
h1 { "Simple Example App" }
nav {
Link {
target: named::<RootIndex>(),
"Go to root"
}
}
Outlet { }
}
}
fn RootIndex(cx: Scope) -> Element {
render! {
h1 { "Simple Example App" }
h2 { "Root Index" }
ul {
li {
Link {
target: "/apple",
"Read about apples…"
}
}
}
}
}
fn Apple(cx: Scope) -> Element {
render! {
h2 { "Apple" }
p {
"An apple is a tasty fruit. It grows on trees and many varieties are either red or "
"green."
}
}
}