Skip to content

Router switch can't pass down query string (and other special parts)  #1575

@siku2

Description

@siku2

Best explained by looking at the following example:

#[derive(Clone, Debug, Switch)]
pub enum PostsRoute {
    #[to = "/{}"]
    Id(u64),
    #[to = "/?page={}"]
    ListPage(u64),
    #[to = "/"]
    List,
}

#[derive(Clone, Debug, Switch)]
pub enum AppRoute {
    #[to = "/posts{*}"]
    Posts(PostsRoute),
}

This feels like it should work. In fact, one of the example in yew-router uses this exact pattern (BRoute is used like PostsRoute here).

The route "/posts/?page=5" will still match PostsRoute::List instead of PostsRoute::ListPage(5) because "?page=5" isn't passed down. PostsRoute only ever receives "/".

This is because {*} stops capturing as soon as it sees " #&?=".
This behaviour is certainly desired when capturing simple values like strings but in this case it's rather unfortunate.

I don't have a proposal to offer because there will be significant changes to the router anyway and this issue should be considered in the new design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions