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,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"
}
}