2023-06-01 22:31:13 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2023-06-22 19:13:51 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2023-06-01 22:31:13 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_router::prelude::*;
|
2023-06-22 01:51:40 +00:00
|
|
|
|
2023-06-22 01:36:32 +00:00
|
|
|
use dioxus_router::ssr::{DefaultRenderer, IncrementalRendererConfig};
|
2023-06-01 22:31:13 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-06-22 01:36:32 +00:00
|
|
|
let mut renderer = IncrementalRendererConfig::new(DefaultRenderer {
|
|
|
|
before_body: r#"<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width,
|
|
|
|
initial-scale=1.0">
|
|
|
|
<title>Dioxus Application</title>
|
|
|
|
</head>
|
|
|
|
<body>"#
|
|
|
|
.to_string(),
|
|
|
|
after_body: r#"</body>
|
|
|
|
</html>"#
|
|
|
|
.to_string(),
|
|
|
|
})
|
|
|
|
.static_dir("./static")
|
2023-06-22 19:13:51 +00:00
|
|
|
.invalidate_after(Duration::from_secs(10))
|
2023-06-22 01:36:32 +00:00
|
|
|
.build();
|
2023-06-01 22:31:13 +00:00
|
|
|
|
2023-06-22 19:13:51 +00:00
|
|
|
renderer.pre_cache_static_routes::<Route>().unwrap();
|
2023-06-01 22:31:13 +00:00
|
|
|
|
2023-06-22 19:13:51 +00:00
|
|
|
for _ in 0..1_000_000 {
|
2023-06-22 01:36:32 +00:00
|
|
|
for id in 0..10 {
|
2023-06-22 19:13:51 +00:00
|
|
|
renderer
|
|
|
|
.render(Route::Post { id }, &mut std::io::sink())
|
|
|
|
.unwrap();
|
2023-06-01 22:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline_props]
|
2023-06-22 01:36:32 +00:00
|
|
|
fn Blog(cx: Scope) -> Element {
|
2023-06-01 22:31:13 +00:00
|
|
|
render! {
|
2023-06-22 01:36:32 +00:00
|
|
|
div {
|
|
|
|
"Blog"
|
2023-06-01 22:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline_props]
|
2023-06-22 01:36:32 +00:00
|
|
|
fn Post(cx: Scope, id: usize) -> Element {
|
2023-06-01 22:31:13 +00:00
|
|
|
render! {
|
|
|
|
div {
|
2023-06-22 01:36:32 +00:00
|
|
|
"PostId: {id}"
|
2023-06-01 22:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline_props]
|
2023-06-22 01:36:32 +00:00
|
|
|
fn PostHome(cx: Scope) -> Element {
|
2023-06-01 22:31:13 +00:00
|
|
|
render! {
|
|
|
|
div {
|
|
|
|
"Post"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline_props]
|
|
|
|
fn Home(cx: Scope) -> Element {
|
|
|
|
render! {
|
|
|
|
div {
|
|
|
|
"Home"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
#[derive(Clone, Debug, PartialEq, Routable)]
|
|
|
|
enum Route {
|
|
|
|
#[nest("/blog")]
|
|
|
|
#[route("/")]
|
|
|
|
Blog {},
|
2023-06-22 01:36:32 +00:00
|
|
|
#[route("/post/index")]
|
|
|
|
PostHome {},
|
|
|
|
#[route("/post/:id")]
|
|
|
|
Post {
|
|
|
|
id: usize,
|
|
|
|
},
|
2023-06-01 22:31:13 +00:00
|
|
|
#[end_nest]
|
|
|
|
#[route("/")]
|
|
|
|
Home {},
|
|
|
|
}
|