prefech wasm + JS by default
This commit is contained in:
1 parent
bfcb0f6eab
commit
5ffdb4dbed
2 files changed
+27
-19
No files matched your search
@@ -41,15 +41,12 @@ fn main() {
|
|||||||
// If the path is unknown, render the application
|
// If the path is unknown, render the application
|
||||||
.fallback(
|
.fallback(
|
||||||
move |uri: http::uri::Uri, State(ssr_state): State<SSRState>| {
|
move |uri: http::uri::Uri, State(ssr_state): State<SSRState>| {
|
||||||
let rendered = ssr_state.render(
|
let rendered = ssr_state.render(&ServeConfig::new(
|
||||||
&ServeConfig::new(
|
App,
|
||||||
App,
|
AppProps {
|
||||||
AppProps {
|
route: Some(format!("http://{addr}{uri}")),
|
||||||
route: Some(format!("http://{addr}{uri}")),
|
},
|
||||||
},
|
));
|
||||||
)
|
|
||||||
.head(r#"<title>Hello World!</title>"#),
|
|
||||||
);
|
|
||||||
async move { axum::body::Full::from(rendered) }
|
async move { axum::body::Full::from(rendered) }
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,25 +20,36 @@ fn dioxus_ssr_html<P: 'static + Clone>(cfg: &ServeConfig<P>, renderer: &mut Rend
|
|||||||
let mut vdom = VirtualDom::new_with_props(*app, props.clone());
|
let mut vdom = VirtualDom::new_with_props(*app, props.clone());
|
||||||
let _ = vdom.rebuild();
|
let _ = vdom.rebuild();
|
||||||
let base_path = base_path.unwrap_or(".");
|
let base_path = base_path.unwrap_or(".");
|
||||||
let head = head.unwrap_or(
|
|
||||||
r#"<title>Dioxus Application</title>
|
|
||||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<meta charset="UTF-8" />"#,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut html = String::new();
|
let mut html = String::new();
|
||||||
|
|
||||||
if let Err(err) = write!(
|
let result = match head {
|
||||||
&mut html,
|
Some(head) => {
|
||||||
r#"
|
write!(
|
||||||
|
&mut html,
|
||||||
|
r#"
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>{head}
|
<head>{head}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="main">"#
|
<div id="main">"#
|
||||||
) {
|
)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
write!(
|
||||||
|
&mut html,
|
||||||
|
r#"<title>Dioxus Application</title>
|
||||||
|
<link rel="preload" href="/{base_path}/assets/dioxus/{application_name}_bg.wasm" as="fetch" type="application/wasm" crossorigin="" />
|
||||||
|
<link rel="modulepreload" href="/{base_path}/assets/dioxus/{application_name}.js" />
|
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta charset="UTF-8" />"#
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = result {
|
||||||
eprintln!("Failed to write to html: {}", err);
|
eprintln!("Failed to write to html: {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user