* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
32 lines
1.0 KiB
Rust
32 lines
1.0 KiB
Rust
//! This example shows how to load in custom assets with the use_asset_handler hook.
|
|
//!
|
|
//! This hook is currently only available on desktop and allows you to intercept any request made by the webview
|
|
//! and respond with your own data. You could use this to load in custom videos, streams, stylesheets, images,
|
|
//! or any asset that isn't known at compile time.
|
|
|
|
use dioxus::desktop::{use_asset_handler, wry::http::Response};
|
|
use dioxus::prelude::*;
|
|
|
|
const STYLE: &str = asset!("./examples/assets/custom_assets.css");
|
|
|
|
fn main() {
|
|
dioxus::LaunchBuilder::desktop().launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
use_asset_handler("logos", |request, response| {
|
|
// We get the original path - make sure you handle that!
|
|
if request.uri().path() != "/logos/logo.png" {
|
|
return;
|
|
}
|
|
|
|
response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
|
|
});
|
|
|
|
rsx! {
|
|
head::Link { rel: "stylesheet", href: STYLE }
|
|
h1 { "Dynamic Assets" }
|
|
img { src: "/logos/logo.png" }
|
|
}
|
|
}
|