DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.19k stars 772 forks source link

Default values for route segments #2781

Open AdrienPensart opened 1 month ago

AdrienPensart commented 1 month ago

Feature Request

I would like to write something like this : #[route("/?:muted=true&:start=10")] there is many url-serde serializer/deserializer for this kind of usecase.

For now, I have to write this :

#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
    #[route("/?:muted&:start")]
    BoxingTimer {
        muted: bool,
        start: u64,
    },
}

#[component]
fn BoxingTimer(
    muted: bool,
    start: bool,
) -> Element {
    if start == 0 {
       start = 10
    }
    if muted {
        mute()
    }
}

thank you for this amazing project!

ealmloff commented 1 month ago

We should allow Option<T> in query and hash segments which tries to parse the inner type and then falls back to None if it fails