* wip: redirect * redirect example * fix file upload not in a form * wip * deny missing cfgs * wip: add router fallback but it's not working * fix suspense bug after rebuilds that queued work * more cleanup * add test for error codes * add helpful comment * bring back middleware annotation * fix cfg * add server feature * fix doctest * just disable liveview test for now * fix liveview * dont send init * cache more playwright! * add more pkgs to cache
51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
//! This example shows how to use the axum `Redirect` type to redirect the client to a different URL.
|
|
//!
|
|
//! On the web, a redirect will not be handled directly by JS, but instead the browser will automatically
|
|
//! follow the redirect. This is useful for redirecting to different pages after a form submission.
|
|
//!
|
|
//! Note that redirects returned to the client won't navigate the SPA to a new page automatically.
|
|
//! For managing a session or auth with client side routing, you'll need to handle that in the SPA itself.
|
|
|
|
use dioxus::{fullstack::Redirect, prelude::*};
|
|
|
|
fn main() {
|
|
dioxus::launch(|| {
|
|
rsx! {
|
|
Router::<Route> {}
|
|
}
|
|
});
|
|
}
|
|
|
|
#[derive(Clone, PartialEq, Routable)]
|
|
enum Route {
|
|
#[route("/")]
|
|
Home,
|
|
|
|
#[route("/blog")]
|
|
Blog,
|
|
}
|
|
|
|
#[component]
|
|
fn Home() -> Element {
|
|
rsx! {
|
|
h1 { "Welcome home" }
|
|
form {
|
|
method: "post",
|
|
action: "/api/old-blog",
|
|
button { "Go to blog" }
|
|
}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Blog() -> Element {
|
|
rsx! {
|
|
h1 { "Welcome to the blog!" }
|
|
}
|
|
}
|
|
|
|
#[post("/api/old-blog")]
|
|
async fn redirect_to_blog() -> Result<Redirect> {
|
|
Ok(Redirect::to("/blog"))
|
|
}
|