dx-utils 0.1.0

Utility functions for Dioxus fullstack apps
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 103.59 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 866.26 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 37s Average build duration of successful builds.
  • all releases: 1m 38s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • TheUnderdev/dx-utils
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TheUnderdev

dx-utils

Utility functions for Dioxus fullstack apps.

Functions

redirect_external(url: &str)

Redirect to an external URL. Works correctly during both SSR and client-side navigation.

  • During SSR: sets HTTP 302 status and a Location header via FullstackContext, producing a real HTTP redirect before any HTML reaches the browser.
  • On the client (post-hydration): uses navigator().replace() with NavigationTarget::External for a client-side navigation.

Usage

Add to your Cargo.toml:

[dependencies]
dx-utils = "0.1"

[features]
server = ["dx-utils/server"]

Then in your component:

use dioxus::prelude::*;
use dx_utils::redirect_external;

#[component]
fn AuthGuard() -> Element {
    let auth = use_server_future(|| check_auth())?;
    let binding = auth.read();
    let status = binding.as_ref().and_then(|r| r.as_ref().ok());

    if let Some(s) = status {
        if !s.authenticated {
            redirect_external(&s.login_url);
            return rsx! {};
        }
    }

    rsx! { Outlet::<Route> {} }
}

Features

Feature Description
server Enables SSR redirect via FullstackContext and http crate

Requirements

  • Dioxus 0.7+
  • Rust 1.75+

License

MIT