Return a 404 when paring the route fails (#3860)

* return a 404 when paring the route fails

* add a playwright test for fullstack routing status codes

* Fix new playwright test

* document SSRError

* Make SSRError public and fix clippy

* Move the error display bound to the routable trait

* fix clippy

* return a more generic 404 message

* fix router tests
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-03-14 00:51:44 -07:00
1 parent 7b7357037f
commit 09a4b5eb4e
18 files changed
+253 -46

No files matched your search

@@ -0,0 +1,3 @@
.dioxus
dist
target
@@ -0,0 +1,17 @@
[package]
name = "dioxus-playwright-fullstack-routing-test"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dioxus = { workspace = true, features = ["fullstack", "router"] }
serde = "1.0.159"
tokio = { workspace = true, features = ["full"], optional = true }
[features]
default = []
server = ["dioxus/server", "dep:tokio"]
web = ["dioxus/web"]
@@ -0,0 +1,54 @@
// This test is used by playwright configured in the root of the repo
// Tests:
// - 200 Routes
// - 404 Routes
// - 500 Routes
#![allow(non_snake_case)]
use dioxus::{prelude::*, CapturedError};
fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(server_only! {
dioxus::fullstack::ServeConfig::builder().enable_out_of_order_streaming()
})
.launch(app);
}
fn app() -> Element {
rsx! { Router::<Route> {} }
}
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
enum Route {
#[route("/")]
Home,
#[route("/blog/:id/")]
Blog { id: i32 },
#[route("/error")]
ThrowsError,
}
#[component]
fn Blog(id: i32) -> Element {
rsx! {
Link { to: Route::Home {}, "Go home" }
"id: {id}"
}
}
#[component]
fn ThrowsError() -> Element {
return Err(RenderError::Aborted(CapturedError::from_display(
"This route tests uncaught errors in the server",
)));
}
#[component]
fn Home() -> Element {
rsx! {
"Home"
}
}