-
Hi. #[component]
fn ByeWorld(text: u8) -> impl IntoView {
view! { <div>"Bye " {text}</div> }
}
async fn greet() -> impl IntoResponse {
let view = view! {
// <ByeWorld text=8 />
<div>"Hello World"</div>
};
let res = render_to_string(move || view);
// HomeTemplate {
// name: String::from("WORLD"),
// }
Html(res.into_owned())
} I am returning greet in axum route. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
let view = view! {
<ByeWorld text=8 />
<div>"Hello World"</div>
};
render_to_string(move || view) this works fine: render_to_string(move || {
view! {
<ByeWorld text=8 />
<div>"Hello World"</div>
}
}) or of course this: let view = move || {
view! {
<ByeWorld text=8 />
<div>"Hello World"</div>
}
};
render_to_string(view).to_string() |
Beta Was this translation helpful? Give feedback.
-
Hi. Thanks a lot. I appreciate it.
|
Beta Was this translation helpful? Give feedback.
If you compare your version to my version above, you'll see that you have a stray semicolon:
This means that what is returned from the closure inside
render_to_string
is not your view, but the unit type()
, which is (helpfully? unhelpfully?) rendered as an empty HTML string. (It's important that()
implementsIntoView
for Reasons, but occasionally causes this footgun.)if you remove that semicolon it should work as you intended.