DioxusLabs/dioxus

Please change the function signature of `dioxus::server::router` to allow users to set the state type

Ouverte

#5 394 ouverte le 20 mars 2026

 (5 commentaires) (0 réaction) (0 personne assignée)Rust (1 655 forks)batch import
enhancementfullstackgood first issue

Métriques du dépôt

Stars
 (36 038 étoiles)
Métriques de merge PR
 (Merge moyen 16j 13h) (9 PRs mergées en 30 j)

Description

Feature Request

I want to be able to set the state type on the router that's created when using the dioxus::server::router function.

Implement Suggestion

The function is located in https://github.com/DioxusLabs/dioxus/blob/main/packages/fullstack-server/src/launch.rs

line 96.

change it from:

pub fn router(app: fn() -> Element) -> Router {
//....
}

to:

pub fn router<State = ()>(app: fn() -> Element) -> Router<State> { // Setting the default to `()` should ensure compatability with existing apps
//....
}

That way I can do this:

dioxus::server::router::<crate::server::state::ArcStore>(App).with_state(store) //  a struct wrapped in an Arc 

You'll probably have to update some of the other functions that expect just a Router like serve.

Guide contributeur