# dx-utils
Utility functions for [Dioxus](https://dioxuslabs.com/) 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`:
```toml
[dependencies]
dx-utils = "0.1"
[features]
server = ["dx-utils/server"]
```
Then in your component:
```rust
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
| `server` | Enables SSR redirect via `FullstackContext` and `http` crate |
## Requirements
- Dioxus 0.7+
- Rust 1.75+
## License
MIT