dioxus/docs/router/examples/outlet.rs

47 lines
861 B
Rust
Raw Normal View History

2023-06-01 22:31:13 +00:00
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_router::prelude::*;
// ANCHOR: outlet
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(Wrapper)]
#[route("/")]
Index {},
}
#[inline_props]
fn Wrapper(cx: Scope) -> Element {
render! {
header { "header" }
// The index route will be rendered here
2023-07-26 01:14:48 +00:00
Outlet::<Route> { }
2023-06-01 22:31:13 +00:00
footer { "footer" }
}
}
#[inline_props]
fn Index(cx: Scope) -> Element {
render! {
h1 { "Index" }
}
}
// ANCHOR_END: outlet
fn App(cx: Scope) -> Element {
render! {
2023-07-26 01:14:48 +00:00
Router::<Route> {}
2023-06-01 22:31:13 +00:00
}
}
fn main() {
let mut vdom = VirtualDom::new(App);
let _ = vdom.rebuild();
let html = dioxus_ssr::render(&vdom);
assert_eq!(
html,
"<header>header</header><h1>Index</h1><footer>footer</footer>"
);
}