Skip to content

Having A Catch-All Route Produce A 404 Status Code #5017

@TheDarkula

Description

@TheDarkula

As an example router:

#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
    #[layout(Frame)]
        #[route("/")]
        Home {},
        #[route("/about")]
        About {},
        #[route("/:..route")]
        PageNotFound { route: Vec<String> },
}

And using the errors example:

fn app() -> Element {
    rsx! {
        ErrorBoundary {
            handle_error: move |err| {
                // To ensure the HTTP status is still set properly, we need to call `commit_error_status`
                let http_error = FullstackContext::commit_error_status(err.error().unwrap());

                // and then we can render some pretty fallback UI
                rsx! { "An error occurred! {http_error:?}" }
            },
            Post {}
        }
    }
}

fn Post() -> Element {
    let post_data = use_loader(move || get_post())?;
    rsx! { p { "{post_data" } }
}

The ErrorBoundary is never hit, because the status code sent is always 200 OK.

Is there a straightforward way to have a catch-all route send an error so that the ErrorBoundary is activated?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions