Using dioxus as a templating engine? #4178
Answered
by
jkelleyrtp
FalkWoldmann
asked this question in
Q&A
-
Hi, I'm a really big fan of using the use axum::response::Html;
use axum::{Router, routing::get};
use dioxus::prelude::*;
use dioxus::ssr::render_element;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(root));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn root() -> Html<String> {
let content = render_element(rsx! {
div {
for i in 0..5 {
"Number: {i}"
}
}
});
println!("{}", content);
Html(content)
} [package]
name = "dioxus-templating-axum"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = "0.8.4"
dioxus = { version = "0.6.3", default-features = false, features = ["ssr", "minimal"] }
tokio = { version = "1.45.0", features = ["full"] } Is this a valid approach and use case for dixous or do I miss anything important? |
Beta Was this translation helpful? Give feedback.
Answered by
jkelleyrtp
May 23, 2025
Replies: 1 comment 1 reply
-
This is valid! You won't get some goodies like macro-based hot-reload, but If you run into issues with components, you might need to use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jkelleyrtp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is valid! You won't get some goodies like macro-based hot-reload, but
render_element
andrender
are designed for this usecase.If you run into issues with components, you might need to use
render
and a virtualdom - that's what we use internally.